@hashicorp/design-system-components 0.9.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/NEW-COMPONENT-CHECKLIST.md +84 -14
  3. package/README.md +2 -2
  4. package/addon/components/hds/alert/index.hbs +35 -0
  5. package/addon/components/hds/alert/index.js +128 -0
  6. package/addon/components/hds/disclosure/index.hbs +1 -1
  7. package/addon/components/hds/disclosure/index.js +4 -0
  8. package/addon/components/hds/dropdown/index.hbs +10 -13
  9. package/addon/components/hds/dropdown/index.js +45 -0
  10. package/addon/components/hds/dropdown/list-item/copy-item.hbs +20 -0
  11. package/addon/components/hds/dropdown/list-item/copy-item.js +55 -0
  12. package/addon/components/hds/dropdown/list-item/description.hbs +3 -0
  13. package/addon/components/hds/dropdown/list-item/description.js +38 -0
  14. package/addon/components/hds/dropdown/list-item/generic.hbs +3 -0
  15. package/addon/components/hds/dropdown/list-item/interactive.hbs +44 -0
  16. package/addon/components/hds/dropdown/list-item/interactive.js +59 -0
  17. package/addon/components/hds/dropdown/list-item/separator.hbs +1 -0
  18. package/addon/components/hds/dropdown/list-item/title.hbs +3 -0
  19. package/addon/components/hds/dropdown/list-item/title.js +35 -0
  20. package/addon/components/hds/dropdown/{toggle-button.hbs → toggle/button.hbs} +3 -3
  21. package/addon/components/hds/dropdown/{toggle-button.js → toggle/button.js} +21 -3
  22. package/addon/components/hds/dropdown/toggle/icon.hbs +12 -0
  23. package/addon/components/hds/dropdown/{toggle-icon.js → toggle/icon.js} +28 -13
  24. package/addon/components/hds/toast/index.hbs +15 -0
  25. package/addon/components/hds/yield/index.hbs +3 -0
  26. package/app/components/hds/{dropdown/list-item.js → alert/index.js} +1 -1
  27. package/app/components/hds/dropdown/list-item/copy-item.js +1 -0
  28. package/app/components/hds/dropdown/list-item/description.js +1 -0
  29. package/app/components/hds/dropdown/list-item/generic.js +1 -0
  30. package/app/components/hds/dropdown/list-item/interactive.js +1 -0
  31. package/app/components/hds/dropdown/list-item/separator.js +1 -0
  32. package/app/components/hds/dropdown/list-item/title.js +1 -0
  33. package/app/components/hds/dropdown/{toggle-button.js → toggle/button.js} +1 -1
  34. package/app/components/hds/dropdown/{toggle-icon.js → toggle/icon.js} +1 -1
  35. package/app/components/hds/toast/index.js +1 -0
  36. package/app/components/hds/yield/index.js +1 -0
  37. package/app/styles/@hashicorp/design-system-components.scss +2 -0
  38. package/app/styles/components/alert.scss +261 -0
  39. package/app/styles/components/breadcrumb.scss +14 -11
  40. package/app/styles/components/button.scss +36 -30
  41. package/app/styles/components/dropdown.scss +152 -151
  42. package/app/styles/components/link/standalone.scss +1 -2
  43. package/app/styles/components/toast.scss +16 -0
  44. package/package.json +27 -26
  45. package/addon/components/hds/dropdown/list-item.hbs +0 -84
  46. package/addon/components/hds/dropdown/list-item.js +0 -120
  47. package/addon/components/hds/dropdown/toggle-icon.hbs +0 -22
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # @hashicorp/design-system-components
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#245](https://github.com/hashicorp/design-system/pull/245) [`c6de1018`](https://github.com/hashicorp/design-system/commit/c6de101880ec1c21971e3775e1a21b6cb9e69757) Thanks [@didoo](https://github.com/didoo)! - - Added `Alert` component
8
+ - Added `Toast` component
9
+
10
+ ### Patch Changes
11
+
12
+ - [#259](https://github.com/hashicorp/design-system/pull/259) [`478b3069`](https://github.com/hashicorp/design-system/commit/478b3069e800cf2ccefba9b5475c72b024e25d16) Thanks [@didoo](https://github.com/didoo)! - - removed autofocus on first item for `Disclosure` component (and as a result also for `Breadcrumb` and `Dropdown` components)
13
+ - updated focus state treatment for `Dropdown` component
14
+
15
+ * [#225](https://github.com/hashicorp/design-system/pull/225) [`f1f07179`](https://github.com/hashicorp/design-system/commit/f1f0717952b3e6b41676135cf00e77a6e55579ec) Thanks [@Dhaulagiri](https://github.com/Dhaulagiri)! - update to ember-keyboard@8.1.0 in packages/components
16
+
17
+ - [#265](https://github.com/hashicorp/design-system/pull/265) [`79bc3e99`](https://github.com/hashicorp/design-system/commit/79bc3e99cd5cc6cb60fc82286d5726c0d0ffbd82) Thanks [@Dhaulagiri](https://github.com/Dhaulagiri)! - npx ember-cli-update@4.3.0 dependency updates
18
+
19
+ * [#253](https://github.com/hashicorp/design-system/pull/253) [`21786983`](https://github.com/hashicorp/design-system/commit/21786983d4ebbb3f38a72d4d105504169bfeda78) Thanks [@MelSumner](https://github.com/MelSumner)! - bugfix for icon size in copy-item component
20
+
21
+ ## 0.10.0
22
+
23
+ ### Minor Changes
24
+
25
+ - [#200](https://github.com/hashicorp/design-system/pull/200) [`a8072537`](https://github.com/hashicorp/design-system/commit/a8072537542791398d375cde4a7a85c2955c66da) Thanks [@didoo](https://github.com/didoo)! - Updated Dropdown component:
26
+
27
+ - added chevron animation for `toggle` elements
28
+ - fixed issue with `list-item/interactive` height
29
+ - added handling of dynamic `width` for the list
30
+ - exposed an `onClose` event
31
+ - removed the default icon for `toggle/icon`
32
+ - removed icon requirement from the `critical` list item
33
+ - updated the documentation and integration tests
34
+ - some code refactorings, reorganizations and cleanups
35
+
36
+ ## 0.9.2
37
+
38
+ ### Patch Changes
39
+
40
+ - [#209](https://github.com/hashicorp/design-system/pull/209) [`6021d433`](https://github.com/hashicorp/design-system/commit/6021d43352b8e38b268b06cd98ca0c62adb14999) Thanks [@didoo](https://github.com/didoo)! - Re-ordered declarations of CSS states
41
+
3
42
  ## 0.9.1
4
43
 
5
44
  ### Patch Changes
@@ -5,34 +5,97 @@ This is the quest issue/engineering checklist for the COMPONENT_NAME Component.
5
5
  ## Pre-Flight Checklist
6
6
  Update this list and these links as appropriate.
7
7
 
8
- - [Component Requirement Document (CRD)](url_here): This file should exist before any code is written.
9
- - [FIGMA Design](url_here): Since we are trying to align the component API naming with the same terms used in the Figma file, it is likely useful to have a fairly stable Figma design before we create a component; it should definitely be finalized before the component ships, however.
10
- - [Design System Website](https://design-system-website.vercel.app/?path=/story/example-introduction--page) (storybook of storybooks): use for reference, to consider existing features that we might need to replicate in the component.
8
+ - [Component Audit](https://www.figma.com/file/h3LtloARmbYVwh7z6XWHVb/Component-Audits-FY23?node-id=0%3A1): This audit should be completed by ambassadors before any work gets started.
9
+ - [Component Requirement Document (CRD)](https://docs.google.com/document/d/1kGcdfnb_z5tVUUvkSJGQPOssNd1yl2SVyd7bqk1KXII/): This file should exist before any design explorations or code is written.
10
+ - ["System of Systems" Storybook](https://unofficial-design-system-search.vercel.app) (storybook of storybooks): use for reference, to consider existing features that we might need to replicate in the component.
11
+
12
+
13
+ ## Design Checklist
14
+ The design checklist has 5 parts:
15
+ 1. creating the branch
16
+ 2. design explorations and iterations
17
+ 3. documentation
18
+ 4. release
19
+ 5. testing
20
+
21
+ The design process is largely cyclical, so some of these steps may need to be repeated until approval.
22
+
23
+ ### Component Creation
24
+ - [ ] [create a branch](https://help.figma.com/hc/en-us/articles/360063144053-Create-branches-and-merge-changes#Create_a_branch) in the [product components ui kit](https://www.figma.com/file/noyY6dUMDYjmySpHcMjhkN/HDS-Product---Components)
25
+ - [ ] add a new page for the component, as needed
26
+ - [ ] copy & paste the [stickersheet template](https://www.figma.com/file/noyY6dUMDYjmySpHcMjhkN/HDS-Product---Components?node-id=2279%3A26800) found in UI Helpers to the new page
27
+ - [ ] update the status badge to "In progress"
28
+ - [ ] change "{DOC TYPE}" to "STICKERSHEET"
29
+ - [ ] change "{Component name}" to the name of the component
30
+ - [ ] delete the sunset notice
31
+ - [ ] **design**
32
+ - [ ] work through design explorations, providing 2-3 visual directions based on existing [foundations](https://www.figma.com/file/oQsMzMMnynfPWpMEt91OpH/HDS-Product---Foundations?node-id=2916%3A4) and patterns, as well as the findings from the audit and requirements from the CRD
33
+ - [ ] review with appropriate stakeholders (typically HDS designers, engineering partner, ambassadors) and iterate
34
+ - [ ] review for a11y considerations and iterate, as necessary
35
+ - [ ] review with design leadership and iterate, as necessary
36
+ - [ ] once approved, build out the design as a component
37
+ - ensure the variant and property names align with what was discussed/decided on with your engineering partner
38
+ - [ ] test the component with HDS designers and iterate, as necessary
39
+ - [ ] sync with your engineering partner (pseudo handoff)
40
+ - let them know it's been design approved and discuss any remaining questions (this should be an ongoing process as well)
41
+ - [ ] **documentation**
42
+ - all documentation should be contained within frames so it can be easily linked to
43
+ - [ ] stickersheet
44
+ - make sure the component instances can be easily selected and other layers are locked
45
+ - [ ] design guidelines
46
+ - when complete, lock this frame
47
+ - [ ] figma tips, as necessary
48
+ - when complete, lock this frame
49
+ - [ ] migration details, as necessary
50
+ - when complete, lock this frame
51
+ - [ ] let your engineering partner know that design guidelines are ready to be added to the scrappy site (they will add it themselves)
52
+ - [ ] **release**
53
+ - [ ] lock and hide the components leaving only the stickersheets and docs visible, and change the header's badge to Experimental
54
+ - [ ] add release notes to the changelog
55
+ - [ ] review with situationally appropriate reviewers to get final approval
56
+ - [ ] merge the branch
57
+ - [ ] publish the ui kit
58
+ - Important: do not communicate this release to consumers yet! (this will be done later in the process)
59
+ - [ ] **testing**
60
+ - [ ] add a new page to the [playground](https://www.figma.com/file/95YqaJF4TNV72ucXbyC7A0/Playground?node-id=302%3A10) file and prepare a frame for each ambassador to test
61
+ - provide a variety (basic to complex) of screenshots to recreate based on real world examples from the audit
62
+ - [ ] test the component with ambassadors
63
+ - if iterations are needed, work through the process until approved (don't forget to branch!)
64
+ - [ ] **final release**
65
+ - this comes after ambassadors have tested the component in Figma and no other adjustments are needed
66
+ - [ ] if changes were required, follow the steps under "release" again
67
+ - [ ] share about the release in the slack channel [#team-design-systems](https://hashicorp.slack.com/archives/C7KTUHNUS) and let consumers know that the component is available for use in Figma
68
+
11
69
 
12
70
  ## Engineering Checklist
13
71
  The engineering checklist has six parts: creating the feature branch, component template, component backing class, component style, tests, and documentation.
14
72
 
73
+ ### Dependency
74
+ - Since we are trying to align the component API naming with the same terms used in the Figma file, it is likely useful to have a fairly stable Figma design before we create a component; it should definitely be finalized before the component ships, however.
75
+
15
76
  ### Component Creation
16
77
 
17
- - [ ] create new branch from main for the component.
78
+ - [ ] create new branch from main for the component (`git checkout -b USER/COMPONENT-NAME`)
18
79
  - [ ] create new component
19
- - `ember generate component hds/COMPONENT_NAME/index --gc` (the component won't need to be invoked with index, it's just to put all the files in the correct place)
20
- - if it's a variation on a component, then `hds/COMPONENT_NAME/VARIATION` instead of `index`
80
+ - `ember generate component hds/COMPONENT-NAME/index --gc` (the component won't need to be invoked with index, it's just to put all the files in the correct place)
81
+ - tip: if you forget to generate the backing class (via `--gc`), you can add it with `ember generate component-class hds/COMPONENT-NAME/index`.
82
+ - if it's a child component, then `hds/COMPONENT_NAME/CHILD_NAME` instead of `index`
83
+ - tip: if you need to destroy a component and start over again, `ember destroy component hds/COMPONENT-NAME/index` will remove the component and the related files as appropriate.
21
84
  - [ ] **component template**
22
85
  - use semantic HTML
23
86
  - the component should have a css class that is the same as the component (e.g. `hds/button` should have a class name of `hds-button` on the component, and additional CSS classes should start with this same class name.
24
87
  - add `...attributes` unless doing so would be detrimental (e.g., a parent element and child element in the same component that both have ...attributes)
25
88
  - [ ] **component class**
26
89
  - use getters (vs template conditionals or constructors, if possible)
27
- - write API comments in the JS doc way (copy from an existing DS component)
28
- - use the same naming as the Figma file for the components API unless it conflicts with a pre-existing HTML attribute. If that is the case, document the difference in the comment.
29
- - ensure that all existing functionality (from a Structure component) is accounted for in some way. If we are not providing existing functionality at all, it should be documented (along with the reason why). If we are providing temporary functionality, explain that it's temporary and why.
30
- - check the [design system website](https://design-system-website.vercel.app/?path=/story/example-introduction--page) to see what kind of component functionality is being used across all products
90
+ - we have chosen to define the value of the `class` attribute (containing the different CSS class names) for the "root" of the element's code in the backing class, UNLESS that component only has one CSS class name.
91
+ - write API comments in the [JS doc](https://jsdoc.app/) format (look at existing components for examples)
92
+ - use the same naming as the Figma file for the components API, unless it conflicts with a pre-existing HTML attribute. If that is the case, document the difference in a comment.
93
+ - if there is an existing Structure component that is similar to the HDS component being created, ensure that all existing functionality is accounted for in some way. If we are not providing existing functionality at all, it should be documented (along with the reason why). If we are providing temporary functionality, explain that it's temporary and why.
31
94
  - booleans should start with a verb (is/has/etc)
32
- - assertion text should match the content style of the other components.
33
- - goal is a terse invocation
95
+ - assertions should match the content style of the other components, e.g., `'@text for "Hds::Button" must have a valid value'`,
96
+ - program with intent; think about the invocation for the developer who will use the component. The goal is a terse invocation, but we also want to consider the big picture. Try to get feedback when you can.
34
97
  - [ ] **component style**
35
- - create `component/COMPONENT_NAME.scss` in `app/styles`
98
+ - create `component/COMPONENT-NAME.scss` in `app/styles`
36
99
  - add `@use` to `app/styles/@hashicorp/design-system-components.scss` (see existing code for precise syntax)
37
100
  - use design tokens wherever possible, comment where they are not
38
101
  - sizes should be in relative units
@@ -42,12 +105,18 @@ The engineering checklist has six parts: creating the feature branch, component
42
105
  - [ ] test defaults
43
106
  - [ ] try not to repeat tests (i.e., don't have to test all sizes, all colors, etc.)
44
107
  - [ ] test all accessibility attributes
108
+ - [ ] test assertions
45
109
  - [ ] **documentation**
46
110
  - create component page `ember generate route components/COMPONENT_NAME --dummy`
47
111
  - add link to `templates/index.hbs` page
48
- - [ ] API docs
112
+ - [ ] Definition of component (from CRD) (this should be a paragraph under the component name, and before the first section)
113
+ - [ ] Component API
49
114
  - [ ] Usage
115
+ - [ ] Design Guidelines
50
116
  - [ ] Accessibility
117
+ - Conformance Rating [(internal document)](https://docs.google.com/document/d/1OjTKpQLB_wuZSVJNLbbguTzMDMYCHKhNdKQz7-Kfqic/edit#bookmark=id.v7r42vfu4pdd)
118
+ - Known Issues (if any)
119
+ - Related WCAG (pull from CRD or ask Melanie)
51
120
  - [ ] Showcase
52
121
 
53
122
  ### Component Review
@@ -69,5 +138,6 @@ Pre-review request checks:
69
138
  - Edge (once available)
70
139
 
71
140
  When ready for review:
141
+
72
142
  - [ ] add situationally appropriate reviewers
73
143
  - [ ] added instructions for reviewers in your PR, letting them know what kind of review you need
package/README.md CHANGED
@@ -9,8 +9,8 @@ A package containing the components for the HashiCorp Design System.
9
9
  Compatibility
10
10
  ------------------------------------------------------------------------------
11
11
 
12
- * Ember.js v3.20 or above
13
- * Ember CLI v3.20 or above
12
+ * Ember.js v3.24 or above
13
+ * Ember CLI v3.24 or above
14
14
  * Node.js v12 or above
15
15
 
16
16
 
@@ -0,0 +1,35 @@
1
+ <div class={{this.classNames}} role="alert" aria-live="polite" ...attributes>
2
+ {{#if this.icon}}
3
+ <div class="hds-alert__icon">
4
+ <FlightIcon @name={{this.icon}} @size={{this.iconSize}} @stretched={{true}} @isInlineBlock={{false}} />
5
+ </div>
6
+ {{/if}}
7
+
8
+ <div class="hds-alert__content">
9
+ <div class="hds-alert__text">
10
+ {{#if @title}}
11
+ <div class="hds-alert__title">{{@title}}</div>
12
+ {{/if}}
13
+ {{#if @description}}
14
+ <div class="hds-alert__description">{{html-safe @description}}</div>
15
+ {{/if}}
16
+ </div>
17
+
18
+ <div class="hds-alert__actions">
19
+ {{yield
20
+ (hash
21
+ Button=(component "hds/button" size="small")
22
+ Link::Standalone=(component "hds/link/standalone" size="small")
23
+ LinkTo::Standalone=(component "hds/link-to/standalone" size="small")
24
+ )
25
+ }}
26
+ </div>
27
+ {{yield (hash Generic=(component "hds/yield"))}}
28
+ </div>
29
+
30
+ {{#if this.onDismiss}}
31
+ <button class="hds-alert__dismiss" type="button" aria-label="Dismiss" {{on "click" this.onDismiss}}>
32
+ <FlightIcon @name="x" @size="16" @isInlineBlock={{false}} />
33
+ </button>
34
+ {{/if}}
35
+ </div>
@@ -0,0 +1,128 @@
1
+ import Component from '@glimmer/component';
2
+ import { assert } from '@ember/debug';
3
+
4
+ export const TYPES = ['page', 'inline', 'compact'];
5
+ export const DEFAULT_COLOR = 'neutral';
6
+ export const COLORS = [
7
+ 'neutral',
8
+ 'highlight',
9
+ 'success',
10
+ 'warning',
11
+ 'critical',
12
+ ];
13
+ export const MAPPING_COLORS_TO_ICONS = {
14
+ neutral: 'info',
15
+ highlight: 'info',
16
+ success: 'check-circle',
17
+ warning: 'alert-triangle',
18
+ critical: 'alert-diamond',
19
+ };
20
+
21
+ export default class HdsAlertIndexComponent extends Component {
22
+ constructor() {
23
+ super(...arguments);
24
+
25
+ assert(
26
+ `@type for "Hds::Alert" must be one of the following: ${TYPES.join(
27
+ ', '
28
+ )}; received: ${this.args.type}`,
29
+ TYPES.includes(this.args.type)
30
+ );
31
+ }
32
+
33
+ /**
34
+ * @param color
35
+ * @type {enum}
36
+ * @default neutral
37
+ * @description Determines the color scheme for the alert.
38
+ */
39
+ get color() {
40
+ let { color = DEFAULT_COLOR } = this.args;
41
+
42
+ assert(
43
+ `@color for "Hds::Alert" must be one of the following: ${COLORS.join(
44
+ ', '
45
+ )}; received: ${color}`,
46
+ COLORS.includes(color)
47
+ );
48
+
49
+ return color;
50
+ }
51
+
52
+ /**
53
+ * @param icon
54
+ * @type {string}
55
+ * @default null
56
+ * @description The name of the icon to be used.
57
+ */
58
+ get icon() {
59
+ let { icon } = this.args;
60
+
61
+ // If `icon` isn't passed, use the pre-defined one from `color`
62
+ if (icon === undefined) {
63
+ if (this.args.type === 'compact') {
64
+ // for the "compact" type by default we use filled icons
65
+ return `${MAPPING_COLORS_TO_ICONS[this.color]}-fill`;
66
+ } else {
67
+ // for all the other types by default we use outlined icons
68
+ return MAPPING_COLORS_TO_ICONS[this.color];
69
+ }
70
+ // If `icon` is set explicitly to false, user doesn't want any icon in the alert
71
+ } else if (icon === false) {
72
+ assert(
73
+ `@icon for "Hds::Alert" with @type "compact" is required`,
74
+ this.args.type !== 'compact'
75
+ );
76
+
77
+ return false;
78
+ } else {
79
+ // If a name for `icon` is passed, set FlightIcon to that name
80
+ return icon;
81
+ }
82
+ }
83
+
84
+ /**
85
+ * @param onDismiss
86
+ * @type {function}
87
+ * @default () => {}
88
+ */
89
+ get onDismiss() {
90
+ let { onDismiss } = this.args;
91
+
92
+ if (typeof onDismiss === 'function') {
93
+ return onDismiss;
94
+ } else {
95
+ return false;
96
+ }
97
+ }
98
+
99
+ /**
100
+ * @param iconSize
101
+ * @type {string}
102
+ * @description ensures that the correct icon size is used. Automatically calculated.
103
+ */
104
+ get iconSize() {
105
+ if (this.args.type === 'compact') {
106
+ return '16';
107
+ } else {
108
+ return '24';
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Get the class names to apply to the component.
114
+ * @method Alert#classNames
115
+ * @return {string} The "class" attribute to apply to the component.
116
+ */
117
+ get classNames() {
118
+ let classes = ['hds-alert'];
119
+
120
+ // Add a class based on the @type argument
121
+ classes.push(`hds-alert--type-${this.args.type}`);
122
+
123
+ // Add a class based on the @color argument
124
+ classes.push(`hds-alert--color-${this.color}`);
125
+
126
+ return classes.join(' ');
127
+ }
128
+ }
@@ -7,7 +7,7 @@
7
7
  class="hds-disclosure__content"
8
8
  {{focus-trap
9
9
  isActive=this.isActive
10
- shouldSelfFocus=false
10
+ shouldSelfFocus=true
11
11
  focusTrapOptions=(hash clickOutsideDeactivates=this.clickOutsideDeactivates onDeactivate=this.onDeactivate)
12
12
  }}
13
13
  >
@@ -38,6 +38,10 @@ export default class HdsDisclosureComponent extends Component {
38
38
  this.isActive = false;
39
39
  // we need to reset this check
40
40
  this.isToggleClicked = false;
41
+ // we call the "onClose" callback if it exists (and is a function)
42
+ if (this.args.onClose && typeof this.args.onClose === 'function') {
43
+ this.args.onClose();
44
+ }
41
45
  }
42
46
  }
43
47
  }
@@ -1,25 +1,22 @@
1
- <Hds::Disclosure class="hds-dropdown">
1
+ <Hds::Disclosure class="hds-dropdown" @onClose={{@onClose}} ...attributes>
2
2
  <:toggle as |t|>
3
3
  {{yield
4
4
  (hash
5
- ToggleButton=(component "hds/dropdown/toggle-button" isOpen=t.isActive onClick=t.onClickToggle)
6
- ToggleIcon=(component "hds/dropdown/toggle-icon" isOpen=t.isActive onClick=t.onClickToggle)
5
+ ToggleButton=(component "hds/dropdown/toggle/button" isOpen=t.isActive onClick=t.onClickToggle)
6
+ ToggleIcon=(component "hds/dropdown/toggle/icon" isOpen=t.isActive onClick=t.onClickToggle)
7
7
  )
8
8
  }}
9
9
  </:toggle>
10
10
  <:content>
11
- <ul
12
- class="hds-dropdown-list
13
- {{if (eq @listPosition 'left') 'hds-dropdown-list--position-left' 'hds-dropdown-list--position-right'}}"
14
- >
11
+ <ul class={{this.listClassNames}} {{style width=@width}}>
15
12
  {{yield
16
13
  (hash
17
- CopyItem=(component "hds/dropdown/list-item" item="copy-item")
18
- Description=(component "hds/dropdown/list-item" item="description")
19
- Generic=(component "hds/dropdown/list-item" item="generic")
20
- Interactive=(component "hds/dropdown/list-item")
21
- Separator=(component "hds/dropdown/list-item" item="separator")
22
- Title=(component "hds/dropdown/list-item" item="title")
14
+ CopyItem=(component "hds/dropdown/list-item/copy-item")
15
+ Description=(component "hds/dropdown/list-item/description")
16
+ Generic=(component "hds/dropdown/list-item/generic")
17
+ Interactive=(component "hds/dropdown/list-item/interactive")
18
+ Separator=(component "hds/dropdown/list-item/separator")
19
+ Title=(component "hds/dropdown/list-item/title")
23
20
  )
24
21
  }}
25
22
  </ul>
@@ -0,0 +1,45 @@
1
+ import Component from '@glimmer/component';
2
+ import { assert } from '@ember/debug';
3
+
4
+ export const DEFAULT_POSITION = 'right';
5
+ export const POSITIONS = ['right', 'left'];
6
+
7
+ export default class HdsDropdownIndexComponent extends Component {
8
+ /**
9
+ * @param listPosition
10
+ * @type {string}
11
+ * @default primary
12
+ * @description Determines the position of the "list"
13
+ */
14
+ get listPosition() {
15
+ let { listPosition = DEFAULT_POSITION } = this.args;
16
+
17
+ assert(
18
+ `@listPosition for "Hds::Dropdown::Index" must be one of the following: ${POSITIONS.join(
19
+ ', '
20
+ )}; received: ${listPosition}`,
21
+ POSITIONS.includes(listPosition)
22
+ );
23
+
24
+ return listPosition;
25
+ }
26
+
27
+ /**
28
+ * Get the class names to apply to the "list"
29
+ * @method DropdownIndex#listClassNames
30
+ * @return {string} The "class" attribute to apply to the "list" element
31
+ */
32
+ get listClassNames() {
33
+ let classes = ['hds-dropdown-list'];
34
+
35
+ // add a class based on the @listPosition argument
36
+ classes.push(`hds-dropdown-list--position-${this.listPosition}`);
37
+
38
+ // add a class based on the @width argument
39
+ if (this.args.width) {
40
+ classes.push('hds-dropdown-list--fixed-width');
41
+ }
42
+
43
+ return classes.join(' ');
44
+ }
45
+ }
@@ -0,0 +1,20 @@
1
+ <li class={{this.classNames}} ...attributes>
2
+ {{#if @copyItemTitle}}
3
+ <div
4
+ class="hds-dropdown-list-item__copy-item-title hds-typography-body-100 hds-font-weight-semibold"
5
+ >{{@copyItemTitle}}</div>
6
+ {{/if}}
7
+ <button
8
+ type="button"
9
+ class="{{if @state (concat 'is-' @state)}} {{if this.isSuccess 'is-success'}}"
10
+ {{on "click" this.copyCode}}
11
+ >
12
+ <div class="hds-dropdown-list-item__copy-item-text hds-typography-code-100">
13
+ {{this.text}}
14
+ </div>
15
+ <FlightIcon
16
+ @name="{{if this.isSuccess 'clipboard-checked' 'clipboard-copy'}}"
17
+ class="hds-dropdown-list-item__copy-item-icon"
18
+ />
19
+ </button>
20
+ </li>
@@ -0,0 +1,55 @@
1
+ import Component from '@glimmer/component';
2
+ import { assert } from '@ember/debug';
3
+ import { tracked } from '@glimmer/tracking';
4
+ import { action } from '@ember/object';
5
+
6
+ export default class HdsDropdownListItemCopyItemComponent extends Component {
7
+ @tracked isSuccess = false;
8
+
9
+ /**
10
+ * @param text
11
+ * @type {string}
12
+ * @description The text of the item. If no text value is defined an error will be thrown
13
+ */
14
+ get text() {
15
+ let { text } = this.args;
16
+
17
+ assert(
18
+ '@text for "Hds::Dropdown::ListItem::CopyItem" must have a valid value',
19
+ text !== undefined
20
+ );
21
+
22
+ return text;
23
+ }
24
+
25
+ /**
26
+ * Get the class names to apply to the component.
27
+ * @method classNames
28
+ * @return {string} The "class" attribute to apply to the component.
29
+ */
30
+ get classNames() {
31
+ let classes = [
32
+ 'hds-dropdown-list-item',
33
+ 'hds-dropdown-list-item--copy-item',
34
+ ];
35
+
36
+ return classes.join(' ');
37
+ }
38
+
39
+ @action
40
+ async copyCode() {
41
+ // https://developer.mozilla.org/en-US/docs/Web/API/Clipboard
42
+ await navigator.clipboard.writeText(this.args.text);
43
+ const result = await navigator.clipboard.readText();
44
+
45
+ if (result === this.args.text) {
46
+ this.isSuccess = true;
47
+ // console.log(`result is ${result}`);
48
+
49
+ // make it fade back to the default state
50
+ setTimeout(() => {
51
+ this.isSuccess = false;
52
+ }, 1000);
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,3 @@
1
+ <li class={{this.classNames}} ...attributes>
2
+ {{this.text}}
3
+ </li>
@@ -0,0 +1,38 @@
1
+ import Component from '@glimmer/component';
2
+ import { assert } from '@ember/debug';
3
+
4
+ export default class HdsDropdownListItemDescriptionComponent extends Component {
5
+ /**
6
+ * @param text
7
+ * @type {string}
8
+ * @description The text of the item. If no text value is defined an error will be thrown
9
+ */
10
+ get text() {
11
+ let { text } = this.args;
12
+
13
+ assert(
14
+ '@text for "Hds::Dropdown::ListItem::Description" must have a valid value',
15
+ text !== undefined
16
+ );
17
+
18
+ return text;
19
+ }
20
+
21
+ /**
22
+ * Get the class names to apply to the component.
23
+ * @method classNames
24
+ * @return {string} The "class" attribute to apply to the component.
25
+ */
26
+ get classNames() {
27
+ let classes = [
28
+ 'hds-dropdown-list-item',
29
+ 'hds-dropdown-list-item--description',
30
+ ];
31
+
32
+ // add classes for the typographic style
33
+ classes.push('hds-typography-body-100');
34
+ classes.push('hds-font-weight-regular');
35
+
36
+ return classes.join(' ');
37
+ }
38
+ }
@@ -0,0 +1,3 @@
1
+ <li class="hds-dropdown-list-item hds-dropdown-list-item--generic" ...attributes>
2
+ {{yield}}
3
+ </li>
@@ -0,0 +1,44 @@
1
+ <li class={{this.classNames}}>
2
+ {{#if @route}}
3
+ <LinkTo
4
+ class="{{if @state (concat 'is-' @state)}}"
5
+ @current-when={{@current-when}}
6
+ @models={{hds-link-to-models @model @models}}
7
+ @query={{hds-link-to-query @query}}
8
+ @replace={{@replace}}
9
+ @route={{@route}}
10
+ ...attributes
11
+ >
12
+ {{#if @icon}}
13
+ <div class="hds-dropdown-list-item__interactive-icon">
14
+ <FlightIcon @name={{@icon}} @isInlineBlock={{false}} />
15
+ </div>
16
+ {{/if}}
17
+ <div class="hds-dropdown-list-item__interactive-text hds-typography-body-200 hds-font-weight-medium">
18
+ {{this.text}}
19
+ </div>
20
+ </LinkTo>
21
+ {{else if @href}}
22
+ <a target="_blank" rel="noopener noreferrer" href={{@href}} class="{{if @state (concat 'is-' @state)}}">
23
+ {{#if @icon}}
24
+ <div class="hds-dropdown-list-item__interactive-icon">
25
+ <FlightIcon @name={{@icon}} @isInlineBlock={{false}} />
26
+ </div>
27
+ {{/if}}
28
+ <div class="hds-dropdown-list-item__interactive-text hds-typography-body-200 hds-font-weight-medium">
29
+ {{this.text}}
30
+ </div>
31
+ </a>
32
+ {{else}}
33
+ <button class="{{if @state (concat 'is-' @state)}}" type="button" ...attributes>
34
+ {{#if @icon}}
35
+ <div class="hds-dropdown-list-item__interactive-icon">
36
+ <FlightIcon @name={{@icon}} @isInlineBlock={{false}} />
37
+ </div>
38
+ {{/if}}
39
+ <div class="hds-dropdown-list-item__interactive-text hds-typography-body-200 hds-font-weight-medium">
40
+ {{this.text}}
41
+ </div>
42
+ </button>
43
+ {{/if}}
44
+ </li>