@hashicorp/design-system-components 0.2.0 → 0.3.2

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,26 @@
1
1
  # @hashicorp/design-system-components
2
2
 
3
+ ## 0.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#112](https://github.com/hashicorp/design-system/pull/112) [`2be08081`](https://github.com/hashicorp/design-system/commit/2be08081582dd7e9c092fdb35c94c063d5ee7f4e) Thanks [@didoo](https://github.com/didoo)! - added missing helpers for “color” and “typography” in “components” package
8
+
9
+ ## 0.3.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#98](https://github.com/hashicorp/design-system/pull/98) [`411cd9b9`](https://github.com/hashicorp/design-system/commit/411cd9b949e376d38eb1dc4d4af93ae17e6c686a) Thanks [@didoo](https://github.com/didoo)! - refactored the “focus-ring” mixins to support both “action” (default) and “critical“ colors
14
+
15
+ - Updated dependencies [[`411cd9b9`](https://github.com/hashicorp/design-system/commit/411cd9b949e376d38eb1dc4d4af93ae17e6c686a)]:
16
+ - @hashicorp/design-system-tokens@0.7.0
17
+
18
+ ## 0.3.0
19
+
20
+ ### Minor Changes
21
+
22
+ - [#48](https://github.com/hashicorp/design-system/pull/48) [`971efb9e`](https://github.com/hashicorp/design-system/commit/971efb9e92478e4d88c24aeee835f448f35d2066) Thanks [@didoo](https://github.com/didoo)! - Added "Breadcrumb" component
23
+
3
24
  ## 0.2.0
4
25
 
5
26
  ### Minor Changes
@@ -0,0 +1,5 @@
1
+ <nav class={{this.classNames}} aria-label="breadcrumbs" ...attributes>
2
+ <ol class="hds-breadcrumb__list" {{did-insert this.didInsert}}>
3
+ {{yield}}
4
+ </ol>
5
+ </nav>
@@ -0,0 +1,40 @@
1
+ import Component from '@glimmer/component';
2
+
3
+ const noop = () => {};
4
+
5
+ export default class HdsBreadcrumbComponent extends Component {
6
+ /**
7
+ * @param onDidInsert
8
+ * @type {function}
9
+ * @default () => {}
10
+ */
11
+ get didInsert() {
12
+ // TODO discuss with Matthew if this is the right way to create a guard for this method
13
+ return this.args.didInsert ?? noop;
14
+ }
15
+
16
+ /**
17
+ * @param itemsCanWrap
18
+ * @type {boolean}
19
+ * @default true
20
+ */
21
+ get itemsCanWrap() {
22
+ return this.args.itemsCanWrap ?? true;
23
+ }
24
+
25
+ /**
26
+ * Get the class names to apply to the component.
27
+ * @method Breadcrumb#classNames
28
+ * @return {string} The "class" attribute to apply to the component.
29
+ */
30
+ get classNames() {
31
+ let classes = ['hds-breadcrumb'];
32
+
33
+ // add a class based on the @itemsCanWrap argument
34
+ if (this.itemsCanWrap) {
35
+ classes.push('hds-breadcrumb--items-can-wrap');
36
+ }
37
+
38
+ return classes.join(' ');
39
+ }
40
+ }
@@ -0,0 +1,26 @@
1
+ <li class="hds-breadcrumb__item" style={{this.itemStyle}} ...attributes>
2
+ {{#if @current}}
3
+ <div class="hds-breadcrumb__current">
4
+ {{#if @icon}}
5
+ <div class="hds-breadcrumb__icon">
6
+ <FlightIcon @name={{@icon}} @size="16" @stretched={{true}} />
7
+ </div>
8
+ {{/if}}
9
+ <span class="hds-breadcrumb__text">{{@text}}</span>
10
+ </div>
11
+ {{else}}
12
+ <LinkTo
13
+ class="hds-breadcrumb__link {{if @hover 'is-hover'}} {{if @active 'is-active'}} {{if @focus 'is-focus'}}"
14
+ @models={{hds-link-to-models @model @models}}
15
+ @query={{hds-link-to-query @query}}
16
+ @route={{@route}}
17
+ >
18
+ {{#if @icon}}
19
+ <div class="hds-breadcrumb__icon">
20
+ <FlightIcon @name={{@icon}} @size="16" @stretched={{true}} />
21
+ </div>
22
+ {{/if}}
23
+ <span class="hds-breadcrumb__text">{{@text}}</span>
24
+ </LinkTo>
25
+ {{/if}}
26
+ </li>
@@ -0,0 +1,50 @@
1
+ import Component from '@glimmer/component';
2
+ import { htmlSafe } from '@ember/template';
3
+ import { assert } from '@ember/debug';
4
+
5
+ export default class HdsBreadcrumbItemComponent extends Component {
6
+ /**
7
+ * @param maxWidth
8
+ * @type {string}
9
+ * @default undefined
10
+ * @description A parameter that can be applied to an "item" to limit its max-width
11
+ */
12
+ get maxWidth() {
13
+ let { maxWidth } = this.args;
14
+
15
+ if (maxWidth) {
16
+ assert(
17
+ `@maxWidth for "Hds::Breadcrumb::Item" must be a size as number in 'px' or in 'em' (eg. '200px' or '24em'), received: ${maxWidth}`,
18
+ maxWidth.match(/^\d+(px|em)$/)
19
+ );
20
+
21
+ return maxWidth;
22
+ } else {
23
+ return undefined;
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Get the inline style to apply to the item.
29
+ * @method BreadcrumbItem#itemStyle
30
+ * @return {string} The "style" attribute to apply to the item.
31
+ */
32
+ get itemStyle() {
33
+ if (this.maxWidth) {
34
+ return htmlSafe(`max-width: ${this.maxWidth}`);
35
+ } else {
36
+ return undefined;
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Get the class names to apply to the component.
42
+ * @method BreadcrumbItem#classNames
43
+ * @return {string} The "class" attribute to apply to the component.
44
+ */
45
+ get classNames() {
46
+ let classes = ['hds-breadcrumb__item'];
47
+
48
+ return classes.join(' ');
49
+ }
50
+ }
@@ -0,0 +1,23 @@
1
+ <li class="hds-breadcrumb__item hds-breadcrumb__item--is-truncation" ...attributes>
2
+ <Hds::Disclosure>
3
+ <:toggle as |t|>
4
+ <button
5
+ type="button"
6
+ class="hds-breadcrumb__truncation-toggle
7
+ {{if @hover 'is-hover'}}
8
+ {{if @active 'is-active'}}
9
+ {{if @focus 'is-focus'}}"
10
+ {{on "click" t.onClickToggle}}
11
+ >
12
+ <FlightIcon @name="more-horizontal" @size="16" @isInlineBlock={{false}} />
13
+ </button>
14
+ </:toggle>
15
+ <:content>
16
+ <div class="hds-breadcrumb__truncation-content">
17
+ <ol class="hds-breadcrumb__sublist">
18
+ {{yield}}
19
+ </ol>
20
+ </div>
21
+ </:content>
22
+ </Hds::Disclosure>
23
+ </li>
@@ -167,7 +167,7 @@ export default class HdsButtonIndexComponent extends Component {
167
167
 
168
168
  /**
169
169
  * Get the class names to apply to the component.
170
- * @method Badge#classNames
170
+ * @method Button#classNames
171
171
  * @return {string} The "class" attribute to apply to the component.
172
172
  */
173
173
  // "hds-button {{this.sizeClass}} {{this.colorClass}} {{this.widthClass}}"
@@ -0,0 +1 @@
1
+ export { default } from '@hashicorp/design-system-components/components/hds/breadcrumb/index';
@@ -0,0 +1 @@
1
+ export { default } from '@hashicorp/design-system-components/components/hds/breadcrumb/item';
@@ -0,0 +1 @@
1
+ export { default } from '@hashicorp/design-system-components/components/hds/breadcrumb/truncation';
@@ -1,10 +1,13 @@
1
1
  // these are files coming from the 'design-system-tokens' package
2
2
  @use "tokens";
3
+ @use "helpers/color";
3
4
  @use "helpers/elevation";
4
5
  @use "helpers/focus-ring";
6
+ @use "helpers/typography";
5
7
 
6
8
  @use "../components/badge";
7
9
  @use "../components/badge-count";
10
+ @use "../components/breadcrumb";
8
11
  @use "../components/button";
9
12
  @use "../components/card";
10
13
  @use "../components/disclosure";
@@ -0,0 +1,189 @@
1
+ //
2
+ // BREADCRUMB
3
+ //
4
+ // properties within each class are sorted alphabetically
5
+ //
6
+ //
7
+
8
+ @use "../mixins/focus-ring" as *;
9
+
10
+ $hds-breadcrumb-item-height: 28px;
11
+ $hds-breadcrumb-item-border-radius: 5px;
12
+ $hds-breadcrumb-item-visual-horizontal-padding: 4px;
13
+
14
+ // MAIN CONTAINER (NAV)
15
+ .hds-breadcrumb {
16
+ position: relative;
17
+ }
18
+
19
+ // LIST (OL)
20
+
21
+ .hds-breadcrumb__list {
22
+ display: flex;
23
+ list-style: none;
24
+ margin: 0;
25
+ padding: 0;
26
+
27
+ .hds-breadcrumb--items-can-wrap & {
28
+ flex-wrap: wrap;
29
+ }
30
+ }
31
+
32
+ .hds-breadcrumb__sublist {
33
+ list-style: none;
34
+ margin: 0;
35
+ padding: 0;
36
+ }
37
+
38
+ // ITEM (LI)
39
+
40
+ .hds-breadcrumb__item {
41
+ align-items: center;
42
+ display: flex;
43
+ flex-direction: row;
44
+ min-width: 0;
45
+ position: relative;
46
+
47
+ .hds-breadcrumb__list > & {
48
+ &:not(:last-child)::after {
49
+ color: var(--token-color-palette-neutral-300);
50
+ content: "/";
51
+ padding: 0 8px;
52
+ }
53
+ }
54
+
55
+ .hds-breadcrumb__sublist > & + & {
56
+ margin-top: 4px;
57
+ }
58
+ }
59
+
60
+ .hds-breadcrumb__item--is-truncation {
61
+ flex: none; // needed to avoid that the "flex" parent collapses the truncation element (it happens with very long strings and no-wrapping)
62
+ }
63
+
64
+ // LINK (A)
65
+
66
+ .hds-breadcrumb__link {
67
+ align-items: center;
68
+ border-radius: $hds-breadcrumb-item-border-radius;
69
+ color: var(--token-color-foreground-faint);
70
+ display: flex;
71
+ flex-direction: row;
72
+ margin: 0 (-$hds-breadcrumb-item-visual-horizontal-padding); // we use a negative horizontal margin to counter-balance the horizonal padding (used to shift the focus from the content)
73
+ min-width: 0;
74
+ padding: 0 $hds-breadcrumb-item-visual-horizontal-padding;
75
+ // notice: the text decoration is applied directly to the "text" container because of a bug in Safari (see https://github.com/hashicorp/design-system-components/issues/159)
76
+ text-decoration-color: transparent;
77
+
78
+ // we apply the focus directly to the element, without using a pseudo-element
79
+ @include hds-focus-ring-basic();
80
+
81
+ &:hover,
82
+ &.is-hover {
83
+ color: var(--token-color-palette-neutral-600);
84
+
85
+ > .hds-breadcrumb__text {
86
+ text-decoration-color: currentColor;
87
+ }
88
+ }
89
+
90
+ &:active,
91
+ &.is-active {
92
+ color: var(--token-color-foreground-secondary);
93
+
94
+ > .hds-breadcrumb__text {
95
+ text-decoration-color: currentColor;
96
+ }
97
+ }
98
+ }
99
+
100
+ // CURRENT
101
+
102
+ .hds-breadcrumb__current {
103
+ align-items: center;
104
+ color: var(--token-color-foreground-strong);
105
+ display: flex;
106
+ flex-direction: row;
107
+ margin: 0 (-$hds-breadcrumb-item-visual-horizontal-padding); // we use a negative horizontal margin to counter-balance the horizonal padding (used to shift the focus from the content)
108
+ min-width: 0;
109
+ padding: 0 $hds-breadcrumb-item-visual-horizontal-padding;
110
+ }
111
+
112
+ // SUB-ELEMENTS
113
+
114
+ .hds-breadcrumb__icon {
115
+ flex: none;
116
+ margin-right: 6px;
117
+ height: 13px;
118
+ width: 13px;
119
+ }
120
+
121
+ .hds-breadcrumb__text {
122
+ font-family: var(--token-typography-font-stack-text);
123
+ font-size: 0.8125rem; // 13px
124
+ line-height: 1rem; // 16px
125
+ overflow: hidden;
126
+ // we use the extra vertical padding to force the height of the parent item to be exactly $hds-breadcrumb-item-height
127
+ padding: calc((#{$hds-breadcrumb-item-height} - 1rem) / 2) 0;
128
+ text-decoration: underline;
129
+ text-decoration-color: transparent;
130
+ text-overflow: ellipsis;
131
+ white-space: nowrap;
132
+
133
+ .hds-breadcrumb__sublist & {
134
+ white-space: normal;
135
+ }
136
+ }
137
+
138
+ // TRUNCATION
139
+
140
+ .hds-breadcrumb__truncation-toggle {
141
+ align-items: center;
142
+ background-color: transparent;
143
+ border: 1px solid transparent; // We need this to be transparent for a11y
144
+ border-radius: $hds-breadcrumb-item-border-radius;
145
+ color: var(--token-color-foreground-faint);
146
+ cursor: pointer;
147
+ display: flex;
148
+ flex: none;
149
+ height: $hds-breadcrumb-item-height;
150
+ justify-content: center;
151
+ margin: 0 (-$hds-breadcrumb-item-visual-horizontal-padding); // the horizontal negative margin applied here is for visual balance of the spacing between items
152
+ outline: none; // TODO check with @melanie
153
+ padding: 0;
154
+ width: $hds-breadcrumb-item-height;
155
+
156
+ // we apply the focus directly to the element, without using a pseudo-element
157
+ @include hds-focus-ring-basic();
158
+
159
+ &:hover,
160
+ &.is-hover {
161
+ border-color: var(--token-color-border-strong);
162
+ color: var(--token-color-foreground-faint);
163
+ }
164
+ &:active,
165
+ &.is-active {
166
+ background-color: var(--token-color-surface-interactive-active);
167
+ border-color: var(--token-color-border-strong);
168
+ color: var(--token-color-foreground-primary);
169
+ }
170
+ &:focus,
171
+ &.is-focus {
172
+ background-color: transparent;
173
+ border: none; // important: we need to completely remove the border, of the inner box-shadow of the focus ring will be drawn inside the border
174
+ }
175
+ }
176
+
177
+ .hds-breadcrumb__truncation-content {
178
+ background-color: var(--token-color-surface-primary);
179
+ border-radius: 6px;
180
+ box-shadow: var(--token-surface-high-box-shadow);
181
+ left: -$hds-breadcrumb-item-visual-horizontal-padding;
182
+ margin-top: 4px;
183
+ max-width: 200px; // by design
184
+ padding: 6px 12px;
185
+ position: absolute;
186
+ top: 100%;
187
+ width: max-content;
188
+ z-index: 300; // this is the z-index used in Structure for this kind of things, I am reusing the same value
189
+ }
@@ -2,14 +2,14 @@
2
2
  // - https://github.com/hashicorp/design-system-components/issues/161
3
3
  // - https://www.tpgi.com/focus-visible-and-backwards-compatibility/
4
4
 
5
- @mixin hds-focus-ring-basic() {
5
+ @mixin hds-focus-ring-basic($color: action) {
6
6
  outline-style: solid; // used to avoid double outline+focus-ring in Safari (see https://github.com/hashicorp/design-system-components/issues/161#issuecomment-1031548656)
7
7
  outline-color: transparent;
8
8
 
9
9
  // default focus for browsers that still rely on ":focus"
10
10
  &:focus,
11
11
  &.is-focus {
12
- box-shadow: var(--token-focus-ring-box-shadow);
12
+ box-shadow: var(--token-focus-ring-#{$color}-box-shadow);
13
13
  }
14
14
  // undo the previous declaration for browsers that support ":focus-visible" but wouldn't normally show default focus styles
15
15
  &:focus:not(:focus-visible) {
@@ -17,7 +17,7 @@
17
17
  }
18
18
  // set focus for browsers that support ":focus-visible"
19
19
  &:focus-visible {
20
- box-shadow: var(--token-focus-ring-box-shadow);
20
+ box-shadow: var(--token-focus-ring-#{$color}-box-shadow);
21
21
  }
22
22
  // remove the focus ring on "active + focused" state (by design)
23
23
  &:focus:active,
@@ -26,7 +26,7 @@
26
26
  }
27
27
  }
28
28
 
29
- @mixin hds-focus-ring-with-pseudo-element($top: 0, $right: 0, $bottom: 0, $left: 0, $radius: 5px) {
29
+ @mixin hds-focus-ring-with-pseudo-element($top: 0, $right: 0, $bottom: 0, $left: 0, $radius: 5px, $color: action) {
30
30
  isolation: isolate; // used to create a new stacking context (needed to have the pseudo element below text/icon but not the parent container)
31
31
  outline-style: solid; // used to avoid double outline+focus-ring in Safari (see https://github.com/hashicorp/design-system-components/issues/161#issuecomment-1031548656)
32
32
  outline-color: transparent;
@@ -48,7 +48,7 @@
48
48
  &:focus,
49
49
  &.is-focus {
50
50
  &::before {
51
- box-shadow: var(--token-focus-ring-box-shadow);
51
+ box-shadow: var(--token-focus-ring-#{$color}-box-shadow);
52
52
  }
53
53
  }
54
54
  // undo the previous declaration for browsers that support ":focus-visible" but wouldn't normally show default focus styles
@@ -60,7 +60,7 @@
60
60
  // set focus for browsers that support ":focus-visible"
61
61
  &:focus-visible {
62
62
  &::before {
63
- box-shadow: var(--token-focus-ring-box-shadow);
63
+ box-shadow: var(--token-focus-ring-#{$color}-box-shadow);
64
64
  }
65
65
  }
66
66
  // remove the focus ring on "active + focused" state (by design)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hashicorp/design-system-components",
3
- "version": "0.2.0",
3
+ "version": "0.3.2",
4
4
  "description": "HashiCorp Design System Components",
5
5
  "keywords": [
6
6
  "hashicorp",
@@ -34,7 +34,7 @@
34
34
  "test:ember:percy": "percy exec ember test"
35
35
  },
36
36
  "dependencies": {
37
- "@hashicorp/design-system-tokens": "^0.6.0",
37
+ "@hashicorp/design-system-tokens": "^0.7.0",
38
38
  "@hashicorp/ember-flight-icons": "^2.0.1",
39
39
  "ember-auto-import": "^2.2.3",
40
40
  "ember-cli-babel": "^7.26.6",