Skip to content

Commit a5a5192

Browse files
shleewhiteshleewhite
andauthored
Form::Fieldset, Form::Header, Text::Display, Form:SuperSelect, Form::TextInput: small type fixes (#3008)
Co-authored-by: shleewhite <[email protected]>
1 parent 2aa0b13 commit a5a5192

File tree

11 files changed

+64
-21
lines changed

11 files changed

+64
-21
lines changed

.changeset/fresh-horses-wink.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@hashicorp/design-system-components": patch
3+
---
4+
5+
<!-- START components/form/super-select -->
6+
`Form::SuperSelect` - fix type for the `@resultCountMessage` argument so it can accept a string or a function.
7+
<!-- END -->

packages/components/src/components/hds/form/fieldset/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import type { HdsFormFieldsetLayouts } from './types.ts';
2121
import type { HdsYieldSignature } from '../../yield/index.ts';
2222
import type { AriaDescribedByComponent } from '../../../../utils/hds-aria-described-by.ts';
2323

24+
export const LAYOUT_TYPES: HdsFormFieldsetLayouts[] = Object.values(
25+
HdsFormFieldsetLayoutValues
26+
);
27+
2428
export interface HdsFormFieldsetSignature {
2529
Args: {
2630
extraAriaDescribedBy?: string;

packages/components/src/components/hds/form/header/title.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { HdsTextDisplaySignature } from '../../text/display.ts';
1313

1414
export const DEFAULT_SIZE = HdsTextSizeValues.FourHundred;
1515
export const DEFAULT_TAG = HdsFormHeaderTitleTagValues.Div;
16-
export const AVAILABLE_TAGS: string[] = Object.values(
16+
export const TAGS: HdsFormHeaderTitleTags[] = Object.values(
1717
HdsFormHeaderTitleTagValues
1818
);
1919

@@ -33,10 +33,10 @@ export default class HdsFormHeaderTitle extends Component<HdsFormHeaderTitleSign
3333
const { tag = DEFAULT_TAG } = this.args;
3434

3535
assert(
36-
`@tag for "Hds::Form::Header::Title" must be one of the following: ${AVAILABLE_TAGS.join(
36+
`@tag for "Hds::Form::Header::Title" must be one of the following: ${TAGS.join(
3737
', '
3838
)}; received: ${tag}`,
39-
AVAILABLE_TAGS.includes(tag)
39+
TAGS.includes(tag)
4040
);
4141

4242
return tag;

packages/components/src/components/hds/form/super-select/multiple/base.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
(component
1313
"hds/form/super-select/after-options"
1414
content=@afterOptionsContent
15-
resultCountMessage=this.resultCountMessage
15+
resultCountMessage=this.resultCountMessageText
1616
showNoSelectedMessage=this._showNoSelectedMessage
1717
showOnlySelected=this._showOnlySelected
1818
showSelected=this.showSelected
@@ -54,7 +54,7 @@
5454
@preventScroll={{@preventScroll}}
5555
@registerAPI={{this.setPowerSelectAPI}}
5656
@renderInPlace={{true}}
57-
@resultCountMessage={{@resultCountMessage}}
57+
@resultCountMessage={{this.resultCountMessageFunction}}
5858
@scrollTo={{@scrollTo}}
5959
@search={{@search}}
6060
@searchEnabled={{@searchEnabled}}

packages/components/src/components/hds/form/super-select/multiple/base.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ export const HORIZONTAL_POSITION_MAPPING =
2424
HdsFormSuperSelectHorizontalPositionToPlacementValues;
2525

2626
export interface HdsFormSuperSelectMultipleBaseSignature {
27-
Args: PowerSelectSignature['Args'] & {
27+
Args: Omit<PowerSelectSignature['Args'], 'resultCountMessage'> & {
2828
showAfterOptions?: boolean;
2929
afterOptionsContent?: string;
30-
resultCountMessage?: string;
30+
resultCountMessage?:
31+
| string
32+
| PowerSelectSignature['Args']['resultCountMessage'];
3133
dropdownMaxWidth?: string;
3234
matchTriggerWidth?: boolean;
3335
isInvalid?: boolean;
@@ -55,8 +57,20 @@ export default class HdsFormSuperSelectMultipleBase extends Component<HdsFormSup
5557
return this._powerSelectAPI?.resultsCount.toString() || '0';
5658
}
5759

58-
get resultCountMessage(): string {
59-
return this.args.resultCountMessage || `${this.optionsCount} total`;
60+
get resultCountMessageText(): string {
61+
if (typeof this.args.resultCountMessage === 'string') {
62+
return this.args.resultCountMessage;
63+
}
64+
65+
return `${this.optionsCount} total`;
66+
}
67+
68+
get resultCountMessageFunction(): PowerSelectSignature['Args']['resultCountMessage'] {
69+
if (typeof this.args.resultCountMessage === 'function') {
70+
return this.args.resultCountMessage;
71+
}
72+
73+
return undefined;
6074
}
6175

6276
@action calculatePosition(

packages/components/src/components/hds/form/super-select/single/base.hbs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
(or
1111
@afterOptionsComponent
1212
(component
13-
"hds/form/super-select/after-options" content=@afterOptionsContent resultCountMessage=this.resultCountMessage
13+
"hds/form/super-select/after-options"
14+
content=@afterOptionsContent
15+
resultCountMessage=this.resultCountMessageText
1416
)
1517
)
1618
}}
@@ -46,7 +48,7 @@
4648
@preventScroll={{@preventScroll}}
4749
@registerAPI={{this.setPowerSelectAPI}}
4850
@renderInPlace={{true}}
49-
@resultCountMessage={{@resultCountMessage}}
51+
@resultCountMessage={{this.resultCountMessageFunction}}
5052
@scrollTo={{@scrollTo}}
5153
@search={{@search}}
5254
@searchEnabled={{@searchEnabled}}

packages/components/src/components/hds/form/super-select/single/base.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ export const HORIZONTAL_POSITION_MAPPING =
2424
HdsFormSuperSelectHorizontalPositionToPlacementValues;
2525

2626
export interface HdsFormSuperSelectSingleBaseSignature {
27-
Args: PowerSelectSignature['Args'] & {
27+
Args: Omit<PowerSelectSignature['Args'], 'resultCountMessage'> & {
2828
showAfterOptions?: boolean;
2929
afterOptionsContent?: string;
30-
resultCountMessage?: string;
30+
resultCountMessage?:
31+
| string
32+
| PowerSelectSignature['Args']['resultCountMessage'];
3133
dropdownMaxWidth?: string;
3234
matchTriggerWidth?: boolean;
3335
isInvalid?: boolean;
@@ -44,10 +46,22 @@ export default class HdsFormSuperSelectSingleBase extends Component<HdsFormSuper
4446
return horizontalPosition as HdsFormSuperSelectHorizontalPositions;
4547
}
4648

47-
get resultCountMessage(): string {
49+
get resultCountMessageText(): string {
50+
if (typeof this.args.resultCountMessage === 'string') {
51+
return this.args.resultCountMessage;
52+
}
53+
4854
return `${this.powerSelectAPI?.resultsCount || 0} total`;
4955
}
5056

57+
get resultCountMessageFunction(): PowerSelectSignature['Args']['resultCountMessage'] {
58+
if (typeof this.args.resultCountMessage === 'function') {
59+
return this.args.resultCountMessage;
60+
}
61+
62+
return undefined;
63+
}
64+
5165
/**
5266
* This action sets the powerSelectAPI property and optionally calls a registerAPI function.
5367
*

packages/components/src/components/hds/form/text-input/base.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import type { HdsFormTextInputTypes } from './types.ts';
1212
// notice: we don't support all the possible HTML types, only a subset
1313
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
1414
export const DEFAULT_TYPE = HdsFormTextInputTypeValues.Text;
15-
export const TYPES: string[] = Object.values(HdsFormTextInputTypeValues);
15+
export const TYPES: HdsFormTextInputTypes[] = Object.values(
16+
HdsFormTextInputTypeValues
17+
);
1618

1719
export interface HdsFormTextInputBaseSignature {
1820
Args: {

packages/components/src/components/hds/text/display.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export const DEFAULT_SIZE = HdsTextSizeValues.TwoHundred;
2121

2222
// Filter out reverse mappings from enum
2323
// https://www.typescriptlang.org/docs/handbook/enums.html#reverse-mappings
24-
export const AVAILABLE_SIZES = Object.values(HdsTextSizeValues).filter(
24+
export const SIZES = Object.values(HdsTextSizeValues).filter(
2525
(v): boolean => typeof v === 'number'
26-
);
26+
) as HdsTextSizes[];
2727

2828
export type HdsTextDisplayWeight = Extract<
2929
HdsTextWeights,
@@ -95,10 +95,10 @@ export default class HdsTextDisplay extends Component<HdsTextDisplaySignature> {
9595
}
9696

9797
assert(
98-
`@size for "Hds::Text::Display" must be one of the following: ${AVAILABLE_SIZES.join(
98+
`@size for "Hds::Text::Display" must be one of the following: ${SIZES.join(
9999
', '
100100
)}; received: ${size}`,
101-
AVAILABLE_SIZES.includes(size)
101+
SIZES.includes(size)
102102
);
103103

104104
return size;

showcase/app/routes/page-components/form/layout.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import Route from '@ember/routing/route';
77

8-
import { AVAILABLE_SIZES as DISPLAY_AVAILABLE_SIZES } from '@hashicorp/design-system-components/components/hds/text/display';
8+
import { SIZES as DISPLAY_AVAILABLE_SIZES } from '@hashicorp/design-system-components/components/hds/text/display';
99
import { DEFAULT_SIZE as FORM_HEADER_TITLE_DEFAULT_SIZE } from '@hashicorp/design-system-components/components/hds/form/header/title';
1010

1111
export default class PageComponentsFormRoute extends Route {

0 commit comments

Comments
 (0)