@hashicorp/design-system-components 0.12.8 → 0.12.9

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @hashicorp/design-system-components
2
2
 
3
+ ## 0.12.9
4
+
5
+ ### Patch Changes
6
+
7
+ - [#418](https://github.com/hashicorp/design-system/pull/418) [`981e2bd9`](https://github.com/hashicorp/design-system/commit/981e2bd99d29398a40274d390d1885ebfcd85133) Thanks [@alex-ju](https://github.com/alex-ju)! - Determine an accessible name for `alertdialog` alerts #418
8
+
9
+ * [#416](https://github.com/hashicorp/design-system/pull/416) [`824e53d1`](https://github.com/hashicorp/design-system/commit/824e53d11678a5bb2544add3d9d1b2a93f9c42c1) Thanks [@alex-ju](https://github.com/alex-ju)! - Remove stray aria-describedby in alert component
10
+
11
+ - [#415](https://github.com/hashicorp/design-system/pull/415) [`c6842109`](https://github.com/hashicorp/design-system/commit/c68421094991b2d62832cb346b4cf23eca1049e4) Thanks [@didoo](https://github.com/didoo)! - Added `@levelHover` and `@levelActive` arguments to `Card::Container` component
12
+
3
13
  ## 0.12.8
4
14
 
5
15
  ### Patch Changes
@@ -1,11 +1,18 @@
1
- <div class={{this.classNames}} role={{this.role}} aria-live="polite" aria-describedby="content" ...attributes>
1
+ <div
2
+ class={{this.classNames}}
3
+ role={{this.role}}
4
+ aria-live="polite"
5
+ aria-labelledby={{this.ariaLabelledBy}}
6
+ {{did-insert this.didInsert}}
7
+ ...attributes
8
+ >
2
9
  {{#if this.icon}}
3
10
  <div class="hds-alert__icon">
4
11
  <FlightIcon @name={{this.icon}} @size={{this.iconSize}} @stretched={{true}} @isInlineBlock={{false}} />
5
12
  </div>
6
13
  {{/if}}
7
14
 
8
- <div class="hds-alert__content" {{did-insert this.didInsertContent}}>
15
+ <div class="hds-alert__content">
9
16
  <div class="hds-alert__text">
10
17
  {{yield (hash Title=(component "hds/alert/title"))}}
11
18
  {{yield (hash Description=(component "hds/alert/description"))}}
@@ -1,6 +1,7 @@
1
1
  import Component from '@glimmer/component';
2
2
  import { action } from '@ember/object';
3
3
  import { assert } from '@ember/debug';
4
+ import { guidFor } from '@ember/object/internals';
4
5
  import { tracked } from '@glimmer/tracking';
5
6
 
6
7
  export const TYPES = ['page', 'inline', 'compact'];
@@ -20,8 +21,13 @@ export const MAPPING_COLORS_TO_ICONS = {
20
21
  critical: 'alert-diamond',
21
22
  };
22
23
 
24
+ const CONTENT_ELEMENT_SELECTOR = '.hds-alert__content';
25
+ const TITLE_ELEMENT_SELECTOR = '.hds-alert__title';
26
+ const DESCRIPTION_ELEMENT_SELECTOR = '.hds-alert__description';
27
+
23
28
  export default class HdsAlertIndexComponent extends Component {
24
29
  @tracked role = 'alert';
30
+ @tracked ariaLabelledBy;
25
31
 
26
32
  constructor() {
27
33
  super(...arguments);
@@ -131,10 +137,23 @@ export default class HdsAlertIndexComponent extends Component {
131
137
  }
132
138
 
133
139
  @action
134
- didInsertContent(element) {
135
- let actions = element.querySelectorAll('button, a');
140
+ didInsert(element) {
141
+ let actions = element.querySelectorAll(
142
+ `${CONTENT_ELEMENT_SELECTOR} button, ${CONTENT_ELEMENT_SELECTOR} a`
143
+ );
136
144
  if (actions.length) {
137
145
  this.role = 'alertdialog';
138
146
  }
147
+
148
+ // `alertdialog` must have an accessible name so we use either the
149
+ // title or the description as label for the alert
150
+ let label =
151
+ element.querySelector(TITLE_ELEMENT_SELECTOR) ||
152
+ element.querySelector(DESCRIPTION_ELEMENT_SELECTOR);
153
+ if (label) {
154
+ let labelId = label.getAttribute('id') || guidFor(element);
155
+ label.setAttribute('id', labelId);
156
+ this.ariaLabelledBy = labelId;
157
+ }
139
158
  }
140
159
  }
@@ -21,7 +21,7 @@ export default class HdsCardContainerComponent extends Component {
21
21
  let { level = DEFAULT_LEVEL } = this.args;
22
22
 
23
23
  assert(
24
- `@level for "Hds::CardContainer" must be one of the following: ${LEVELS.join(
24
+ `@level for "Hds::Card::Container" must be one of the following: ${LEVELS.join(
25
25
  ', '
26
26
  )}, received: ${level}`,
27
27
  LEVELS.includes(level)
@@ -30,6 +30,50 @@ export default class HdsCardContainerComponent extends Component {
30
30
  return level;
31
31
  }
32
32
 
33
+ /**
34
+ * Sets the "elevation" level for the component on ":hover" state
35
+ * Accepted values: base, mid, high
36
+ *
37
+ * @param levelHover
38
+ * @type {string}
39
+ */
40
+ get levelHover() {
41
+ let { levelHover } = this.args;
42
+
43
+ if (levelHover) {
44
+ assert(
45
+ `@levelHover for "Hds::Card::Container" must be one of the following: ${LEVELS.join(
46
+ ', '
47
+ )}, received: ${levelHover}`,
48
+ LEVELS.includes(levelHover)
49
+ );
50
+ }
51
+
52
+ return levelHover;
53
+ }
54
+
55
+ /**
56
+ * Sets the "elevation" level for the component on ":active" state
57
+ * Accepted values: base, mid, high
58
+ *
59
+ * @param levelActive
60
+ * @type {string}
61
+ */
62
+ get levelActive() {
63
+ let { levelActive } = this.args;
64
+
65
+ if (levelActive) {
66
+ assert(
67
+ `@levelActive for "Hds::Card::Container" must be one of the following: ${LEVELS.join(
68
+ ', '
69
+ )}, received: ${levelActive}`,
70
+ LEVELS.includes(levelActive)
71
+ );
72
+ }
73
+
74
+ return levelActive;
75
+ }
76
+
33
77
  /**
34
78
  * Sets the background for the component
35
79
  * Accepted values: neutral-primary, neutral-secondary
@@ -42,7 +86,7 @@ export default class HdsCardContainerComponent extends Component {
42
86
  let { background = DEFAULT_BACKGROUND } = this.args;
43
87
 
44
88
  assert(
45
- `@background for "Hds::CardContainer" must be one of the following: ${BACKGROUNDS.join(
89
+ `@background for "Hds::Card::Container" must be one of the following: ${BACKGROUNDS.join(
46
90
  ', '
47
91
  )}, received: ${background}`,
48
92
  BACKGROUNDS.includes(background)
@@ -63,7 +107,7 @@ export default class HdsCardContainerComponent extends Component {
63
107
  let { overflow = DEFAULT_OVERFLOW } = this.args;
64
108
 
65
109
  assert(
66
- `@overflow for "Hds::CardContainer" must be one of the following: ${OVERFLOWS.join(
110
+ `@overflow for "Hds::Card::Container" must be one of the following: ${OVERFLOWS.join(
67
111
  ', '
68
112
  )}, received: ${overflow}`,
69
113
  OVERFLOWS.includes(overflow)
@@ -80,10 +124,26 @@ export default class HdsCardContainerComponent extends Component {
80
124
  get classNames() {
81
125
  let classes = ['hds-card__container'];
82
126
 
83
- // add an "elevation" class helper based on the @level and @hasBorder arguments
127
+ // add "elevation" classes based on the @level and @hasBorder arguments
84
128
  classes.push(
85
- `hds-${this.args.hasBorder ? 'surface' : 'elevation'}-${this.level}`
129
+ `hds-card__container--level-${
130
+ this.args.hasBorder ? 'surface' : 'elevation'
131
+ }-${this.level}`
86
132
  );
133
+ if (this.levelHover) {
134
+ classes.push(
135
+ `hds-card__container--hover-level-${
136
+ this.args.hasBorder ? 'surface' : 'elevation'
137
+ }-${this.levelHover}`
138
+ );
139
+ }
140
+ if (this.levelActive) {
141
+ classes.push(
142
+ `hds-card__container--active-level-${
143
+ this.args.hasBorder ? 'surface' : 'elevation'
144
+ }-${this.levelActive}`
145
+ );
146
+ }
87
147
 
88
148
  // add a class based on the @background argument
89
149
  classes.push(`hds-card__container--background-${this.background}`);
@@ -6,6 +6,7 @@
6
6
  //
7
7
 
8
8
 
9
+ $hds-card-container-style: ( 'surface', 'elevation' );
9
10
  $hds-card-container-levels: ( 'base', 'mid', 'high' );
10
11
 
11
12
  $hds-card-container-border-radius: 6px;
@@ -16,6 +17,30 @@ $hds-card-container-border-radius: 6px;
16
17
  position: relative;
17
18
  }
18
19
 
20
+ // LEVEL (elevation style as "drop" + "border" shadow effects)
21
+
22
+ @each $style in $hds-card-container-style {
23
+ // IMPORTANT: we need to keep separate loops, because we want the "hover" state
24
+ // to override the "rest" state, and the "active" state to override the "hover" state
25
+ // so the order of the declaration matters, they need to be one group after another group
26
+ @each $level in $hds-card-container-levels {
27
+ .hds-card__container--level-#{$style}-#{$level} {
28
+ box-shadow: var(--token-#{$style}-#{$level}-box-shadow);
29
+ }
30
+ }
31
+ @each $level in $hds-card-container-levels {
32
+ .hds-card__container--hover-level-#{$style}-#{$level}:hover,
33
+ .hds-card__container--hover-level-#{$style}-#{$level}.mock-hover {
34
+ box-shadow: var(--token-#{$style}-#{$level}-box-shadow);
35
+ }
36
+ }
37
+ @each $level in $hds-card-container-levels {
38
+ .hds-card__container--active-level-#{$style}-#{$level}:active,
39
+ .hds-card__container--active-level-#{$style}-#{$level}.mock-active {
40
+ box-shadow: var(--token-#{$style}-#{$level}-box-shadow);
41
+ }
42
+ }
43
+ }
19
44
 
20
45
  // BACKGROUND
21
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashicorp/design-system-components",
3
- "version": "0.12.8",
3
+ "version": "0.12.9",
4
4
  "description": "HashiCorp Design System Components",
5
5
  "keywords": [
6
6
  "hashicorp",