Git Product home page Git Product logo

ember-polaris's Introduction

ember-polaris

image

ember-polaris is an ember-cli addon to make Shopify's Polaris design system accessible to Ember developers.

Status

NOTE: this addon is still in development. As such, not all of the components available in the React component library have been built yet, and some features of those which have been built are currently unimplemented. Check the component list for a list of those which are currently available.

Compatibility

  • Ember.js v3.16 or above
  • Ember CLI v2.13 or above
  • Node.js v10 or above

Installation

Install ember-polaris using ember-cli:

$ ember install @smile-io/ember-polaris

Styles

This addon will install ember-cli-sass in the host app. It will also set up your app's app/styles/app.scss to @import "ember-polaris";, creating the file if it does not already exist.

Icons

For icons to work you will need to:

  • copy Polaris SVG's into a folder in public, ex: public/assets/images/svg/polaris
  • install ember-svg-jar
  • add the following ember-svg-jar options to your ember-cli-build.js:
// ember-cli-build.js
var app = new EmberApp(defaults, {
  ...

  svgJar: {
    strategy: 'inline',
    inline: {
      stripPath: false,
      optimizer: {
        removeDimensions: true,
      },
      sourceDirs: [
        'public/assets/images/svg',
      ],
    }
  },

  ...
});

Template compiler

If your app does not already import ember-template-compiler, you may get an error similar to this one when passing a hash of componentName and props into one of the ember-polaris components:

Uncaught TypeError: _ember.default.HTMLBars.compile is not a function

If that happens, you need to add an import statement to its ember-cli-build.js.

// ember-cli-build.js
app.import('node_modules/ember-source/dist/ember-template-compiler.js');

NOTE: This setup will be handled by ember-polaris in the future.

Usage

ember-polaris provides a set of Ember components intended to implement the same behavior and functionality as the Shopify Polaris React components. In general the usage can be inferred from the Polaris component documentation, with some exceptions as described below.

Differences with Polaris React components

We have tried to keep the components provided by ember-polaris as similar to the original Polaris React components as possible. However, there are cases where it makes sense to do things in a more Ember-friendly way, and where this is true we will describe the ember-polaris usage and how it differs from the original Shopify components.

General Differences

children property

A large number of the Polaris React components have a children property listed in their documentation. In these cases, the corresponding ember-polaris component can be given a text attribute which will take the place of the children property and specify the text to be rendered by the component. Alternatively these components can be used in block form to achieve the same result. Note that the block content will take precedence over the text attribute (if one is supplied):

{{polaris-button text="Attribute text"}}
 => renders a button with the content "Attribute text"

{{#polaris-button}}
  Block text
{{/polaris-button}}
 => renders a button with the content "Block text"

{{#polaris-button text="Attribute text"}}
  Block text
{{/polaris-button}}
 => renders a button with the content "Block text"
element property

Some Polaris React components accept an element property which changes the tag rendered by the component. In ember-polaris, this is replaced by the tagName attribute unless otherwise noted. This attribute cannot be dynamic - the following code would cause an error:

{{#polaris-display-text tagName=displayTextTagName}}
  Displays fine to start with...
{{/polaris-display-text}}

{{#polaris-button onClick=(action (mut displayTextTagName) "h5")}}
  ... but clicking this button will cause an error
{{/polaris-button}}
actions property

Some Polaris React components accept an actions property as a list of actions which can be performed. In ember-polaris, this is renamed to avoid collisions with the Ember actions hash. The new name will be different based on the component - check the documentation for the specific component to find out what attribute to pass the actions list as.

Components

Below is a categorised list of the components available in ember-polaris. Click an item to see more information and usage examples for that component.

Actions

Images and icons

Feedback indicators

Structure

Titles and text

Forms

Lists and tables

Navigation

Overlays

Contributing

See the Contributing guide for details.

Release preparation

ember-polaris has an automated changelog generator when preparing releases. Run yarn changelog-generator to generate changelog for the current branch.

License

This project is licensed under the MIT License.

ember-polaris's People

Contributors

andrewpye avatar dependabot-preview[bot] avatar dependabot[bot] avatar kmcgaire avatar matt297 avatar nahrivera7 avatar renovate-bot avatar robinsharma avatar sivakumar-kailasam avatar tomnez avatar vladucu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-polaris's Issues

Border on focussed button in segmented button group displays badly

The React implementation of ButtonGroup.Item adds a class when focussed, which bumps the z-index from 10 up to 20 to prevent this ugliness:

image

I've quickly tried replicating this in the Ember component but divs don't seem to be capable of firing focus/blur (or in Ember land, focusIn/focusOut) actions. That or the button inside the button group icon is stealing the focus/blur events, not sure... either way, this needs fixing, but is quite low priority as not many people will see it.

Update to latest Polaris

We currently use Polaris v1.1.1 - we should update to the latest Polaris release (at the time of writing, v1.10.2). Below is a list of what needs updating to catch up:

Install Polaris styles dynamically

Currently this addon has a copy of the Polaris SASS files in its vendor folder - we should leverage the install process to pull these files dynamically and remove them from this addon.

Component documentation links are broken on npm

The links in the README to the docs pages for each individual component give a 404 when clicked on npm. I've opened an issue with npm to find out what the correct way of linking those is as the fix I attempted in #135 didn't actually fix the issue. One possibility would be to use HTML link tags instead of markdown, and specify the URL ourselves... would like to know what the correct way of doing this would be as well though ๐Ÿ˜‰

polaris-text-field prevents click events when losing focus after updating value

Repro steps

  1. Set up a page with a polaris-text-field and a polaris-button on it.
  2. Focus the text field, enter some text and click the button.

Expected result
Button action fires.

Actual result
Button action does not fire.

I've confirmed that this is not an issue with the original React component.

Example - clicking the page secondary action here should always open a modal, but does not when the text field is focussed and has an updated value:
polaris-text-field-bug

Breadcrumb onAction handler gets passed click event object

Switching an app over to use the new breadcrumb implementation, I found that the click event from the polaris-breadcrumb button element's onclick handler was being passed to the outside world on action invocation, which is messy and in my case, caused an error in the action being invoked.

Make style import friendlier

Currently users have to @import "polaris/styles.scss" in their app to pull in the Polaris styles. We should change this to @import "ember-polaris" if possible.

Enforce enum values

A number of the components in this addon take enum attributes. We should assert that these attributes are given valid values.

Support plain CSS

This addon currently only makes Polaris styles available via SASS. We should support plain CSS as well, since not all host apps will have the option to use SASS.

Set up demo page

We should set up the dummy app as a demo page and host it via GitHub pages

Action list item's button submits parent form

In the following scenario, the button click on the polaris-action-list/item will submit the form that the list is nested inside of:

<form onsubmit={{action "submitted"}}>
  {{polaris-action-list
    items=(array
      (hash
        text="Click me"
        onAction=(action "onClick")
      )
    )
  }}
</form>
import Controller from '@ember/controller';

export default Controller.extend({
  actions: {
    onClick() {
      alert('action list item clicked.')
    },

    submitted() {
      alert('form submitted.');
    }
  }
});

The page also reloads after the form submits. The above implementation is not likely to be used, but this has also happened in other popular form addons such as ember-form-for.

As a quick test, I added an event.preventDefault(); here in the onItemAction and it seemed to fix the issue.

Demo gif:
form

Spinner does not obey `color` attribute

The spinner SVG has a fill attribute on it which causes the image to always be grey. We need to remove this attribute as we do in polaris-icon, so we should probably abstract this behaviour into a mixin and reuse it in polaris-spinner. However, the latter is tagless, so we'll need to find some reliable way of grabbing the spinner's SVG element.

Add Sticky component

We need this to be able to port the ResourceList component across from React-land ๐Ÿ˜„

Original Sticky component source is here. We will also need a StickyManager service, React source here.

Refactor ActionList and sub components

Our implementation of polaris-action-list seems a bit out of date and different from the way the React component is structured.

Our polaris-action-list/item component takes only a single item object attribute, when it should really be taking item attributes:

  • id
  • badge
  • content
  • url
  • onAction
  • icon
  • image
  • disabled
  • external
  • destructive
  • ellipsis
  • active
  • role

This is just one example where the components differ, we should check all of them thoroughly. Also some of these attributes we currently don't have implemented so we should add anything that's been missing.

Document render-content

render-content is useful in many cases where we need to support either text/component being passed in is one of the fields of the polaris components.

This needs to be included in the docs along with any limitations it may have.

Pagination - add new attributes

New nextKeys, previousKeys, nextTooltip, and previousTooltip attributes added with some new event listeners to handle keypress events.

Look into proper import of icon SVG files

The initial implementation of the polaris-icon component has a few nasties around SVG import, such as having to add svg options to the host app's ember-cli-build.js. We should look into how we do this properly.

polaris-select considers wrong item selected on initialisation

Noticed that on first initialisation, polaris-select always seems to consider the first option selected irrespective of the value passed in; this doesn't seem to be an issue in the React implementation.

In the GIF below, the selected value is stripe, but the control shows the checkmark next to the first item (shopify), which prevents that first option being clickable until another option has been clicked:

polaris-select-bug

Priority of Components

Needed components in admin:

  • Page component
  • Titles and text (not really a component but need to import the polaris typography)
  • Action buttons (default, primary, link buttons)
  • Table (unavailable in code - using an Ember each in the app for now)
  • Form input - #17 but available via our ember-form-for wrappers
  • Layout
  • Form layout
  • Form select - available via our ember-form-for wrappers
  • Card
  • Badge
  • Resource List
  • Overlays - Modal
  • Pagination
  • Stack

Nice to haves:

  • Icon
  • Main navigation (not available in code)
  • Overlays - Popover (for logout)
  • Tabs (if we decide to use them)
  • Progress Spinners (unavailable in code, also if we decide to use them)
  • Tooltip (optional for helper states)
  • Link

Changes to underlying data don't trigger `polaris-data-table` cell size recalculation

If a polaris-data-table is being used to render data and e.g. a new item is added or the content of a cell is updated, the code to set row heights etc. doesn't run. This can leave table row heights too big/small for their content.

We might be able to handle this by bubbling an action from polaris-data-table/cell's didRender hook up to the polaris-data-table component and triggering the height recalculation from there.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.