@justeattakeaway/pie-select 0.2.0 → 0.3.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.
package/dist/index.js CHANGED
@@ -1,104 +1,171 @@
1
- import { LitElement as u, nothing as x, html as b, unsafeCSS as y } from "lit";
2
- import { RtlMixin as I, validPropertyValues as f, defineCustomElement as k } from "@justeattakeaway/pie-webc-core";
3
- import { property as c, query as z, queryAssignedElements as $, state as w } from "lit/decorators.js";
4
- import { ifDefined as d } from "lit/directives/if-defined.js";
5
- import { classMap as _ } from "lit/directives/class-map.js";
1
+ import { LitElement as b, html as c, nothing as _, unsafeCSS as $ } from "lit";
2
+ import { FormControlMixin as I, RtlMixin as k, wrapNativeEvent as z, validPropertyValues as f, defineCustomElement as w } from "@justeattakeaway/pie-webc-core";
3
+ import { property as l, query as m, queryAssignedElements as C, state as L } from "lit/decorators.js";
4
+ import { ifDefined as n } from "lit/directives/if-defined.js";
5
+ import { classMap as S } from "lit/directives/class-map.js";
6
+ import { live as T } from "lit/directives/live.js";
6
7
  import "@justeattakeaway/pie-icons-webc/dist/IconChevronDown.js";
7
- const L = "*,*:after,*:before{box-sizing:inherit}.c-select{--select-padding-block: var(--dt-spacing-c);--select-padding-inline-start: var(--dt-spacing-d);--select-padding-inline-end: var(--dt-spacing-h);--select-background-color: var(--dt-color-container-default);--select-text-color: var(--dt-color-content-default);--select-border-color: var(--dt-color-border-form);--select-font-size: calc(var(--dt-font-body-l-size) * 1px);--select-line-height: calc(var(--dt-font-body-l-line-height) * 1px);--select-height: 48px;--select-cursor: pointer;position:relative;color:var(--select-text-color);font-size:var(--select-font-size);line-height:var(--select-line-height)}.c-select select{height:var(--select-height);width:100%;border:1px solid var(--select-border-color);border-radius:var(--dt-radius-rounded-c);padding-inline-start:var(--select-padding-inline-start);padding-inline-end:var(--select-padding-inline-end);padding-block-start:var(--select-padding-block);padding-block-end:var(--select-padding-block);background-color:var(--select-background-color);font-size:inherit;line-height:inherit;color:inherit;outline:0;-webkit-appearance:none;-moz-appearance:none;appearance:none;cursor:var(--select-cursor)}.c-select select:focus-within{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-select.c-select--small{--select-padding-block: var(--dt-spacing-b);--select-height: 40px}.c-select.c-select--large{--select-padding-block: var(--dt-spacing-d);--select-height: 56px}.c-select.c-select--error{--select-border-color: var(--dt-color-support-error)}.c-select.c-select--withLeadingIcon{--select-padding-inline-start: calc(var(--dt-spacing-h) - var(--dt-spacing-a))}.c-select ::slotted([slot=leadingIcon]),.c-select .c-select-trailingIcon{position:absolute;top:50%;transform:translateY(-50%);pointer-events:none}.c-select:not(.is-disabled) ::slotted([slot=leadingIcon]),.c-select:not(.is-disabled) .c-select-trailingIcon{color:var(--dt-color-content-subdued)}.c-select ::slotted([slot=leadingIcon]){--icon-display-override: block;--icon-size-override: 24px;inset-inline-start:var(--dt-spacing-d)}.c-select .c-select-trailingIcon{inset-inline-end:var(--dt-spacing-d)}@media (hover: hover){.c-select:hover{--select-background-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-hover-01))))}@supports (background-color: color-mix(in srgb,black,white)){.c-select:hover{--select-background-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-container-default))}}}.c-select.is-disabled{--select-background-color: var(--dt-color-disabled-01);--select-border-color: var(--dt-color-disabled-01);--select-text-color: var(--dt-color-content-disabled);--select-cursor: auto}", T = ["small", "medium", "large"], S = ["default", "error"], i = {
8
+ import "@justeattakeaway/pie-assistive-text";
9
+ const E = "*,*:after,*:before{box-sizing:inherit}.c-select{--select-padding-block: var(--dt-spacing-c);--select-padding-inline-start: var(--dt-spacing-d);--select-padding-inline-end: var(--dt-spacing-h);--select-background-color: var(--dt-color-container-default);--select-text-color: var(--dt-color-content-default);--select-border-color: var(--dt-color-border-form);--select-font-size: calc(var(--dt-font-body-l-size) * 1px);--select-line-height: calc(var(--dt-font-body-l-line-height) * 1px);--select-height: 48px;--select-cursor: pointer;position:relative;color:var(--select-text-color);font-size:var(--select-font-size);line-height:var(--select-line-height)}.c-select select{height:var(--select-height);width:100%;border:1px solid var(--select-border-color);border-radius:var(--dt-radius-rounded-c);padding-inline-start:var(--select-padding-inline-start);padding-inline-end:var(--select-padding-inline-end);padding-block-start:var(--select-padding-block);padding-block-end:var(--select-padding-block);background-color:var(--select-background-color);font-size:inherit;line-height:inherit;color:inherit;outline:0;-webkit-appearance:none;-moz-appearance:none;appearance:none;cursor:var(--select-cursor)}.c-select select:focus-within{box-shadow:0 0 0 2px var(--dt-color-focus-inner),0 0 0 4px var(--dt-color-focus-outer);outline:none}.c-select.c-select--small{--select-padding-block: var(--dt-spacing-b);--select-height: 40px}.c-select.c-select--large{--select-padding-block: var(--dt-spacing-d);--select-height: 56px}.c-select.c-select--error{--select-border-color: var(--dt-color-support-error)}.c-select.c-select--withLeadingIcon{--select-padding-inline-start: calc(var(--dt-spacing-h) - var(--dt-spacing-a))}.c-select ::slotted([slot=leadingIcon]),.c-select .c-select-trailingIcon{position:absolute;top:50%;transform:translateY(-50%);pointer-events:none}.c-select:not(.is-disabled) ::slotted([slot=leadingIcon]),.c-select:not(.is-disabled) .c-select-trailingIcon{color:var(--dt-color-content-subdued)}.c-select ::slotted([slot=leadingIcon]){--icon-display-override: block;--icon-size-override: 24px;inset-inline-start:var(--dt-spacing-d)}.c-select .c-select-trailingIcon{inset-inline-end:var(--dt-spacing-d)}@media (hover: hover){.c-select:hover{--select-background-color: hsl(var(--dt-color-container-default-h), var(--dt-color-container-default-s), calc(var(--dt-color-container-default-l) + calc(-1 * var(--dt-color-hover-01))))}@supports (background-color: color-mix(in srgb,black,white)){.c-select:hover{--select-background-color: color-mix(in srgb, var(--dt-color-hover-01-bg) var(--dt-color-hover-01), var(--dt-color-container-default))}}}.c-select.is-disabled{--select-background-color: var(--dt-color-disabled-01);--select-border-color: var(--dt-color-disabled-01);--select-text-color: var(--dt-color-content-disabled);--select-cursor: auto}", A = ["small", "medium", "large"], F = ["default", "error"], r = {
8
10
  size: "medium",
9
11
  status: "default",
10
- disabled: !1
12
+ disabled: !1,
13
+ options: []
11
14
  };
12
- var C = Object.defineProperty, s = (h, a, o, n) => {
13
- for (var t = void 0, r = h.length - 1, l; r >= 0; r--)
14
- (l = h[r]) && (t = l(a, o, t) || t);
15
- return t && C(a, o, t), t;
15
+ var V = Object.defineProperty, o = (v, t, e, d) => {
16
+ for (var i = void 0, a = v.length - 1, p; a >= 0; a--)
17
+ (p = v[a]) && (i = p(t, e, i) || i);
18
+ return i && V(t, e, i), i;
16
19
  };
17
- const v = "pie-select", g = "assistive-text", p = class p extends I(u) {
20
+ const g = "pie-select", u = "assistive-text", h = class h extends I(k(b)) {
18
21
  constructor() {
19
- super(...arguments), this.size = i.size, this.disabled = i.disabled, this.status = i.status, this._hasLeadingIcon = !1;
22
+ super(...arguments), this.size = r.size, this.disabled = r.disabled, this.status = r.status, this.options = r.options, this._hasLeadingIcon = !1, this._handleChange = (t) => {
23
+ const e = z(t);
24
+ this.dispatchEvent(e), this._internals.setFormValue(this._select.value);
25
+ };
26
+ }
27
+ firstUpdated() {
28
+ this._internals.setFormValue(this._select.value);
29
+ }
30
+ /**
31
+ * (Read-only) returns a ValidityState with the validity states that this element is in.
32
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
33
+ */
34
+ get validity() {
35
+ return this._select.validity;
36
+ }
37
+ /**
38
+ * Called after the disabled state of the element changes,
39
+ * either because the disabled attribute of this element was added or removed;
40
+ * or because the disabled state changed on a <fieldset> that's an ancestor of this element.
41
+ * @param disabled - The latest disabled state of the select.
42
+ */
43
+ formDisabledCallback(t) {
44
+ this.disabled = t;
45
+ }
46
+ /**
47
+ * Called when the form that owns this component is reset.
48
+ * Resets the value to the default select value.
49
+ */
50
+ formResetCallback() {
51
+ const t = this._select.querySelector("option[selected]");
52
+ this._select.value = (t == null ? void 0 : t.getAttribute("value")) ?? "", this._select.selectedIndex = t ? this._select.selectedIndex : 0, this._internals.setFormValue(this._select.value);
20
53
  }
21
54
  _handleLeadingIconSlotchange() {
22
55
  this._hasLeadingIcon = !!this._leadingIconSlot.length;
23
56
  }
57
+ /**
58
+ * Renders the options from the options property
59
+ * @param options - The options to render
60
+ * @returns A template result with the rendered options
61
+ */
62
+ renderChildren(t) {
63
+ return c`
64
+ ${t.map((e) => e.tag === "optgroup" ? c`
65
+ <optgroup
66
+ ?disabled="${e.disabled}"
67
+ label="${n(e.label)}">
68
+ ${this.renderChildren(e.options)}
69
+ </optgroup>
70
+ ` : c`
71
+ <option
72
+ .value="${T(e.value)}"
73
+ ?disabled="${e.disabled}"
74
+ ?selected="${e.selected}">
75
+ ${e.text}
76
+ </option>
77
+ `)}
78
+ `;
79
+ }
80
+ /**
81
+ * Renders the assistive text if available.
82
+ * @returns A template result with the assistive text
83
+ */
24
84
  renderAssistiveText() {
25
- return this.assistiveText ? b`
85
+ return this.assistiveText ? c`
26
86
  <pie-assistive-text
27
- id="${g}"
28
- variant=${d(this.status)}
29
- data-test-id="pie-textarea-assistive-text">
87
+ id="${u}"
88
+ variant="${n(this.status)}"
89
+ data-test-id="pie-select-assistive-text">
30
90
  ${this.assistiveText}
31
91
  </pie-assistive-text>
32
- ` : x;
92
+ ` : _;
33
93
  }
34
94
  render() {
35
95
  const {
36
- assistiveText: a,
37
- disabled: o,
38
- status: n,
39
- size: t,
40
- name: r,
41
- _hasLeadingIcon: l
42
- } = this, m = {
96
+ assistiveText: t,
97
+ disabled: e,
98
+ status: d,
99
+ size: i,
100
+ name: a,
101
+ options: p,
102
+ _hasLeadingIcon: x
103
+ } = this, y = {
43
104
  "c-select": !0,
44
- [`c-select--${t}`]: !0,
45
- [`c-select--${n}`]: !0,
46
- "c-select--withLeadingIcon": l,
47
- "is-disabled": o
105
+ [`c-select--${i}`]: !0,
106
+ [`c-select--${d}`]: !0,
107
+ "c-select--withLeadingIcon": x,
108
+ "is-disabled": e
48
109
  };
49
- return b`
110
+ return c`
50
111
  <div
51
- class="${_(m)}"
112
+ class="${S(y)}"
52
113
  data-test-id="pie-select-shell">
53
- <slot name="leadingIcon" @slotchange=${this._handleLeadingIconSlotchange}></slot>
54
- <select
55
- name=${d(r)}
56
- ?disabled=${o}
57
- aria-describedby=${d(a ? g : void 0)}
58
- aria-invalid=${n === "error" ? "true" : "false"}
59
- aria-errormessage="${d(n === "error" ? g : void 0)}">
60
- <option value="dog">Dog</option>
61
- <option value="cat">Cat</option>
62
- <option value="hamster">Hamster</option>
63
- </select>
64
- <icon-chevron-down size='s' class='c-select-trailingIcon'></icon-chevron-down>
114
+ <slot name="leadingIcon" @slotchange=${this._handleLeadingIconSlotchange}></slot>
115
+ <select
116
+ data-test-id="pie-select-element"
117
+ name="${n(a)}"
118
+ ?disabled="${e}"
119
+ aria-describedby="${n(t ? u : void 0)}"
120
+ aria-invalid="${d === "error" ? "true" : "false"}"
121
+ aria-errormessage="${n(d === "error" ? u : void 0)}"
122
+ @change=${this._handleChange}>
123
+ ${this.renderChildren(p)}
124
+ </select>
125
+ <icon-chevron-down size='s' class='c-select-trailingIcon'></icon-chevron-down>
65
126
  </div>
66
127
  ${this.renderAssistiveText()}
67
128
  `;
68
129
  }
69
130
  };
70
- p.shadowRootOptions = { ...u.shadowRootOptions, delegatesFocus: !0 }, p.styles = y(L);
71
- let e = p;
72
- s([
73
- c({ type: String }),
74
- f(v, T, i.size)
75
- ], e.prototype, "size");
76
- s([
77
- c({ type: Boolean })
78
- ], e.prototype, "disabled");
79
- s([
80
- c({ type: String }),
81
- f(v, S, i.status)
82
- ], e.prototype, "status");
83
- s([
84
- c({ type: String })
85
- ], e.prototype, "assistiveText");
86
- s([
87
- c({ type: String })
88
- ], e.prototype, "name");
89
- s([
90
- z("select")
91
- ], e.prototype, "focusTarget");
92
- s([
93
- $({ slot: "leadingIcon", flatten: !0 })
94
- ], e.prototype, "_leadingIconSlot");
95
- s([
96
- w()
97
- ], e.prototype, "_hasLeadingIcon");
98
- k(v, e);
131
+ h.shadowRootOptions = { ...b.shadowRootOptions, delegatesFocus: !0 }, h.styles = $(E);
132
+ let s = h;
133
+ o([
134
+ l({ type: String }),
135
+ f(g, A, r.size)
136
+ ], s.prototype, "size");
137
+ o([
138
+ l({ type: Boolean })
139
+ ], s.prototype, "disabled");
140
+ o([
141
+ l({ type: String }),
142
+ f(g, F, r.status)
143
+ ], s.prototype, "status");
144
+ o([
145
+ l({ type: String })
146
+ ], s.prototype, "assistiveText");
147
+ o([
148
+ l({ type: String })
149
+ ], s.prototype, "name");
150
+ o([
151
+ l({ type: Array })
152
+ ], s.prototype, "options");
153
+ o([
154
+ m("select")
155
+ ], s.prototype, "focusTarget");
156
+ o([
157
+ m("select")
158
+ ], s.prototype, "_select");
159
+ o([
160
+ C({ slot: "leadingIcon", flatten: !0 })
161
+ ], s.prototype, "_leadingIconSlot");
162
+ o([
163
+ L()
164
+ ], s.prototype, "_hasLeadingIcon");
165
+ w(g, s);
99
166
  export {
100
- e as PieSelect,
101
- i as defaultProps,
102
- T as sizes,
103
- S as statusTypes
167
+ s as PieSelect,
168
+ r as defaultProps,
169
+ A as sizes,
170
+ F as statusTypes
104
171
  };
package/dist/react.d.ts CHANGED
@@ -1,7 +1,156 @@
1
- import * as React from 'react';
2
- import { PieSelect as PieSelectLit } from './index';
3
- import { type SelectProps } from './defs';
4
- export * from './defs';
5
- type ReactBaseType = React.HTMLAttributes<HTMLSelectElement>;
6
- export declare const PieSelect: React.ForwardRefExoticComponent<SelectProps & React.RefAttributes<PieSelectLit> & ReactBaseType>;
7
- //# sourceMappingURL=react.d.ts.map
1
+ import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
2
+ import type { CSSResult } from 'lit';
3
+ import type { FormControlInterface } from '@justeattakeaway/pie-webc-core';
4
+ import type { GenericConstructor } from '@justeattakeaway/pie-webc-core';
5
+ import type { LitElement } from 'lit';
6
+ import * as React_2 from 'react';
7
+ import type { RTLInterface } from '@justeattakeaway/pie-webc-core';
8
+ import type { TemplateResult } from 'lit';
9
+
10
+ declare type DefaultProps = ComponentDefaultProps<SelectProps, keyof Omit<SelectProps, 'name' | 'assistiveText'>>;
11
+
12
+ export declare const defaultProps: DefaultProps;
13
+
14
+ export declare const PieSelect: React_2.ForwardRefExoticComponent<SelectProps & React_2.RefAttributes<PieSelect_2> & PieSelectEvents & ReactBaseType>;
15
+
16
+ /**
17
+ * @tagname pie-select
18
+ * @event {CustomEvent} change - when the selected option is changed.
19
+ */
20
+ declare class PieSelect_2 extends PieSelect_base implements SelectProps {
21
+ static shadowRootOptions: {
22
+ delegatesFocus: boolean;
23
+ mode: ShadowRootMode;
24
+ slotAssignment?: SlotAssignmentMode | undefined;
25
+ };
26
+ size: "small" | "medium" | "large";
27
+ disabled: boolean;
28
+ status: "default" | "error";
29
+ assistiveText: SelectProps['assistiveText'];
30
+ name: SelectProps['name'];
31
+ options: SelectProps['options'];
32
+ focusTarget: HTMLSelectElement;
33
+ private _select;
34
+ private _leadingIconSlot;
35
+ private _hasLeadingIcon;
36
+ protected firstUpdated(): void;
37
+ /**
38
+ * (Read-only) returns a ValidityState with the validity states that this element is in.
39
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/validity
40
+ */
41
+ get validity(): ValidityState;
42
+ /**
43
+ * Called after the disabled state of the element changes,
44
+ * either because the disabled attribute of this element was added or removed;
45
+ * or because the disabled state changed on a <fieldset> that's an ancestor of this element.
46
+ * @param disabled - The latest disabled state of the select.
47
+ */
48
+ formDisabledCallback(disabled: boolean): void;
49
+ /**
50
+ * Called when the form that owns this component is reset.
51
+ * Resets the value to the default select value.
52
+ */
53
+ formResetCallback(): void;
54
+ /**
55
+ * Captures the native change event and wraps it in a custom event.
56
+ * @param event - The change event.
57
+ */
58
+ private _handleChange;
59
+ private _handleLeadingIconSlotchange;
60
+ /**
61
+ * Renders the options from the options property
62
+ * @param options - The options to render
63
+ * @returns A template result with the rendered options
64
+ */
65
+ private renderChildren;
66
+ /**
67
+ * Renders the assistive text if available.
68
+ * @returns A template result with the assistive text
69
+ */
70
+ private renderAssistiveText;
71
+ render(): TemplateResult<1>;
72
+ static styles: CSSResult;
73
+ }
74
+
75
+ declare const PieSelect_base: GenericConstructor<FormControlInterface> & GenericConstructor<RTLInterface> & typeof LitElement;
76
+
77
+ declare type PieSelectEvents = {
78
+ onChange?: (event: CustomEvent) => void;
79
+ };
80
+
81
+ declare type ReactBaseType = React_2.HTMLAttributes<HTMLSelectElement>;
82
+
83
+ declare interface SelectOptionGroupProps {
84
+ /**
85
+ * What HTML element the option should be such option or optgroup.
86
+ */
87
+ tag: 'optgroup';
88
+ /**
89
+ * The label for the select option group.
90
+ */
91
+ label?: string;
92
+ /**
93
+ * The options within the select option group.
94
+ */
95
+ options: SelectOptionProps[];
96
+ /**
97
+ * Same as the HTML disabled attribute - indicates whether the select option group is disabled.
98
+ */
99
+ disabled?: boolean;
100
+ }
101
+
102
+ declare interface SelectOptionProps {
103
+ /**
104
+ * What HTML element the option should be such option or optgroup.
105
+ */
106
+ tag: 'option';
107
+ /**
108
+ * The text content to display for the select option.
109
+ */
110
+ text: string;
111
+ /**
112
+ * The value of the select option (used as a key/value pair in HTML forms with `name`).
113
+ */
114
+ value?: string;
115
+ /**
116
+ * Same as the HTML disabled attribute - indicates whether the select option is disabled.
117
+ */
118
+ disabled?: boolean;
119
+ /**
120
+ * Same as the HTML selected attribute - indicates whether the select option is selected by default when the page first loads.
121
+ */
122
+ selected?: boolean;
123
+ }
124
+
125
+ export declare interface SelectProps {
126
+ /**
127
+ * The size of the select component. Can be `small`, `medium` or `large`. Defaults to `medium`.
128
+ */
129
+ size?: typeof sizes[number];
130
+ /**
131
+ * Same as the HTML disabled attribute - indicates whether the select is disabled.
132
+ */
133
+ disabled?: boolean;
134
+ /**
135
+ * An optional assistive text to display below the select element. Must be provided when the status is error.
136
+ */
137
+ assistiveText?: string;
138
+ /**
139
+ * The status of the select component / assistive text. Can be default or error.
140
+ */
141
+ status?: typeof statusTypes[number];
142
+ /**
143
+ * The name of the select (used as a key/value pair with `value`). This is required in order to work properly with forms.
144
+ */
145
+ name?: string;
146
+ /**
147
+ * The options to display in the select. Can be an array of option objects or option group objects.
148
+ */
149
+ options: (SelectOptionProps | SelectOptionGroupProps)[];
150
+ }
151
+
152
+ export declare const sizes: readonly ["small", "medium", "large"];
153
+
154
+ export declare const statusTypes: readonly ["default", "error"];
155
+
156
+ export { }
package/dist/react.js CHANGED
@@ -1,13 +1,16 @@
1
1
  import * as e from "react";
2
2
  import { createComponent as t } from "@lit/react";
3
- import { PieSelect as s } from "./index.js";
3
+ import { PieSelect as a } from "./index.js";
4
4
  import { defaultProps as l, sizes as p, statusTypes as n } from "./index.js";
5
5
  const o = t({
6
6
  displayName: "PieSelect",
7
- elementClass: s,
7
+ elementClass: a,
8
8
  react: e,
9
9
  tagName: "pie-select",
10
- events: {}
10
+ events: {
11
+ onChange: "change"
12
+ // when the selected option is changed.
13
+ }
11
14
  }), r = o;
12
15
  export {
13
16
  r as PieSelect,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-select",
3
3
  "description": "PIE Design System Select built using Web Components",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -38,6 +38,7 @@
38
38
  "cem-plugin-module-file-extensions": "0.0.5"
39
39
  },
40
40
  "dependencies": {
41
+ "@justeattakeaway/pie-assistive-text": "0.8.5",
41
42
  "@justeattakeaway/pie-webc-core": "0.24.2"
42
43
  },
43
44
  "volta": {
package/src/defs.ts CHANGED
@@ -4,6 +4,55 @@ export const sizes = ['small', 'medium', 'large'] as const;
4
4
 
5
5
  export const statusTypes = ['default', 'error'] as const;
6
6
 
7
+ interface SelectOptionProps {
8
+ /**
9
+ * What HTML element the option should be such option or optgroup.
10
+ */
11
+ tag: 'option';
12
+
13
+ /**
14
+ * The text content to display for the select option.
15
+ */
16
+ text: string;
17
+
18
+ /**
19
+ * The value of the select option (used as a key/value pair in HTML forms with `name`).
20
+ */
21
+ value?: string;
22
+
23
+ /**
24
+ * Same as the HTML disabled attribute - indicates whether the select option is disabled.
25
+ */
26
+ disabled?: boolean;
27
+
28
+ /**
29
+ * Same as the HTML selected attribute - indicates whether the select option is selected by default when the page first loads.
30
+ */
31
+ selected?: boolean;
32
+ }
33
+
34
+ interface SelectOptionGroupProps {
35
+ /**
36
+ * What HTML element the option should be such option or optgroup.
37
+ */
38
+ tag: 'optgroup';
39
+
40
+ /**
41
+ * The label for the select option group.
42
+ */
43
+ label?: string;
44
+
45
+ /**
46
+ * The options within the select option group.
47
+ */
48
+ options: SelectOptionProps[];
49
+
50
+ /**
51
+ * Same as the HTML disabled attribute - indicates whether the select option group is disabled.
52
+ */
53
+ disabled?: boolean;
54
+ }
55
+
7
56
  export interface SelectProps {
8
57
  /**
9
58
  * The size of the select component. Can be `small`, `medium` or `large`. Defaults to `medium`.
@@ -16,7 +65,7 @@ export interface SelectProps {
16
65
  disabled?: boolean;
17
66
 
18
67
  /**
19
- * An optional assistive text to display below the select element. Must be provided when the status is success or error.
68
+ * An optional assistive text to display below the select element. Must be provided when the status is error.
20
69
  */
21
70
  assistiveText?: string;
22
71
 
@@ -29,12 +78,18 @@ export interface SelectProps {
29
78
  * The name of the select (used as a key/value pair with `value`). This is required in order to work properly with forms.
30
79
  */
31
80
  name?: string;
81
+
82
+ /**
83
+ * The options to display in the select. Can be an array of option objects or option group objects.
84
+ */
85
+ options: (SelectOptionProps | SelectOptionGroupProps)[];
32
86
  }
33
87
 
34
- type DefaultProps = ComponentDefaultProps<SelectProps, keyof Omit<SelectProps, 'name' | 'assistiveText' >>;
88
+ type DefaultProps = ComponentDefaultProps<SelectProps, keyof Omit<SelectProps, 'name' | 'assistiveText'>>;
35
89
 
36
90
  export const defaultProps: DefaultProps = {
37
91
  size: 'medium',
38
92
  status: 'default',
39
93
  disabled: false,
94
+ options: [],
40
95
  };