Skip to content

Commit 74ce502

Browse files
committed
refactor(chip): add stricter types
1 parent 55cac74 commit 74ce502

3 files changed

Lines changed: 29 additions & 28 deletions

File tree

core/src/components.d.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { AlertButton, AlertInput } from "./components/alert/alert-interface";
1414
import { RouteID, RouterDirection, RouterEventDetail, RouteWrite } from "./components/router/utils/interface";
1515
import { BreadcrumbCollapsedClickEventDetail } from "./components/breadcrumb/breadcrumb-interface";
1616
import { CheckboxChangeEventDetail } from "./components/checkbox/checkbox-interface";
17+
import { IonChipFill, IonChipHue, IonChipShape, IonChipSize } from "./components/chip/chip.interfaces";
1718
import { ScrollBaseDetail, ScrollDetail } from "./components/content/content-interface";
1819
import { DatetimeChangeEventDetail, DatetimeHighlight, DatetimeHighlightCallback, DatetimeHourCycle, DatetimePresentation, FormatOptions, TitleSelectedDatesFormatter } from "./components/datetime/datetime-interface";
1920
import { SpinnerTypes } from "./components/spinner/spinner-configs";
@@ -52,6 +53,7 @@ export { AlertButton, AlertInput } from "./components/alert/alert-interface";
5253
export { RouteID, RouterDirection, RouterEventDetail, RouteWrite } from "./components/router/utils/interface";
5354
export { BreadcrumbCollapsedClickEventDetail } from "./components/breadcrumb/breadcrumb-interface";
5455
export { CheckboxChangeEventDetail } from "./components/checkbox/checkbox-interface";
56+
export { IonChipFill, IonChipHue, IonChipShape, IonChipSize } from "./components/chip/chip.interfaces";
5557
export { ScrollBaseDetail, ScrollDetail } from "./components/content/content-interface";
5658
export { DatetimeChangeEventDetail, DatetimeHighlight, DatetimeHighlightCallback, DatetimeHourCycle, DatetimePresentation, FormatOptions, TitleSelectedDatesFormatter } from "./components/datetime/datetime-interface";
5759
export { SpinnerTypes } from "./components/spinner/spinner-configs";
@@ -874,11 +876,11 @@ export namespace Components {
874876
/**
875877
* The fill for the chip. Set to `"outline"` for a chip with a border and background. Set to `"solid"` for a chip with a background. Defaults to `"solid"`.
876878
*/
877-
"fill"?: 'outline' | 'solid';
879+
"fill"?: IonChipFill;
878880
/**
879881
* Set to `"bold"` for a chip with vibrant, bold colors or to `"subtle"` for a chip with muted, subtle colors. Defaults to `"subtle"`.
880882
*/
881-
"hue"?: 'bold' | 'subtle';
883+
"hue"?: IonChipHue;
882884
/**
883885
* The mode determines the platform behaviors of the component.
884886
*/
@@ -892,11 +894,11 @@ export namespace Components {
892894
/**
893895
* Set to `"soft"` for a chip with slightly rounded corners, `"round"` for a chip with fully rounded corners, or `"rectangular"` for a chip without rounded corners. Defaults to `"round"`.
894896
*/
895-
"shape"?: 'soft' | 'round' | 'rectangular';
897+
"shape"?: IonChipShape;
896898
/**
897899
* Set to `"small"` for a chip with less height and padding. Defaults to `"large"`.
898900
*/
899-
"size"?: 'small' | 'large';
901+
"size"?: IonChipSize;
900902
}
901903
interface IonCol {
902904
/**
@@ -6848,11 +6850,11 @@ declare namespace LocalJSX {
68486850
/**
68496851
* The fill for the chip. Set to `"outline"` for a chip with a border and background. Set to `"solid"` for a chip with a background. Defaults to `"solid"`.
68506852
*/
6851-
"fill"?: 'outline' | 'solid';
6853+
"fill"?: IonChipFill;
68526854
/**
68536855
* Set to `"bold"` for a chip with vibrant, bold colors or to `"subtle"` for a chip with muted, subtle colors. Defaults to `"subtle"`.
68546856
*/
6855-
"hue"?: 'bold' | 'subtle';
6857+
"hue"?: IonChipHue;
68566858
/**
68576859
* The mode determines the platform behaviors of the component.
68586860
*/
@@ -6866,11 +6868,11 @@ declare namespace LocalJSX {
68666868
/**
68676869
* Set to `"soft"` for a chip with slightly rounded corners, `"round"` for a chip with fully rounded corners, or `"rectangular"` for a chip without rounded corners. Defaults to `"round"`.
68686870
*/
6869-
"shape"?: 'soft' | 'round' | 'rectangular';
6871+
"shape"?: IonChipShape;
68706872
/**
68716873
* Set to `"small"` for a chip with less height and padding. Defaults to `"large"`.
68726874
*/
6873-
"size"?: 'small' | 'large';
6875+
"size"?: IonChipSize;
68746876
}
68756877
interface IonCol {
68766878
/**

core/src/components/chip/chip.interfaces.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@ export type IonChipRecipe = {
1313

1414
// Hues with fills
1515
hue?: {
16-
bold?: IonChipFillDefinition;
17-
subtle?: IonChipFillDefinition;
16+
[K in IonChipHue]?: IonChipFillDefinition;
1817
};
1918

2019
// Sizes
2120
size?: {
22-
small?: IonChipSizeDefinition;
23-
large?: IonChipSizeDefinition;
21+
[K in IonChipSize]?: IonChipSizeDefinition;
2422
};
2523

2624
// Shapes
2725
shape?: {
28-
soft?: IonChipShapeDefinition;
29-
round?: IonChipShapeDefinition;
30-
rectangular?: IonChipShapeDefinition;
26+
[K in IonChipShape]?: IonChipShapeDefinition;
3127
};
3228

3329
// Shared States
@@ -50,11 +46,7 @@ export type IonChipRecipe = {
5046
};
5147

5248
type IonChipFillDefinition = {
53-
solid?: IonChipStateDefinition & {
54-
semantic?: IonChipStateDefinition;
55-
};
56-
57-
outline?: IonChipStateDefinition & {
49+
[K in IonChipFill]?: IonChipStateDefinition & {
5850
semantic?: IonChipStateDefinition;
5951
};
6052
};
@@ -118,8 +110,13 @@ type IonChipAvatarDefinition = IonChipMediaDefinition & {
118110
};
119111

120112
export type IonChipConfig = {
121-
fill?: 'outline' | 'solid';
122-
hue?: 'bold' | 'subtle';
123-
size?: 'small' | 'large';
124-
shape?: 'soft' | 'round' | 'rectangular';
113+
fill?: IonChipFill;
114+
hue?: IonChipHue;
115+
size?: IonChipSize;
116+
shape?: IonChipShape;
125117
};
118+
119+
export type IonChipFill = 'outline' | 'solid';
120+
export type IonChipHue = 'bold' | 'subtle';
121+
export type IonChipSize = 'small' | 'large';
122+
export type IonChipShape = 'soft' | 'round' | 'rectangular';

core/src/components/chip/chip.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { createColorClasses } from '@utils/theme';
66
import { config } from '../../global/config';
77
import type { Color } from '../../interface';
88

9+
import type { IonChipFill, IonChipHue, IonChipSize, IonChipShape } from './chip.interfaces';
10+
911
/**
1012
* @virtualProp {"ios" | "md"} mode - The mode determines the platform behaviors of the component.
1113
*/
@@ -39,7 +41,7 @@ export class Chip implements ComponentInterface {
3941
*
4042
* Defaults to `"solid"`.
4143
*/
42-
@Prop() fill?: 'outline' | 'solid';
44+
@Prop() fill?: IonChipFill;
4345

4446
/**
4547
* If `true`, the user cannot interact with the chip.
@@ -52,7 +54,7 @@ export class Chip implements ComponentInterface {
5254
*
5355
* Defaults to `"subtle"`.
5456
*/
55-
@Prop() hue?: 'bold' | 'subtle';
57+
@Prop() hue?: IonChipHue;
5658

5759
/**
5860
* Set to `"soft"` for a chip with slightly rounded corners,
@@ -61,15 +63,15 @@ export class Chip implements ComponentInterface {
6163
*
6264
* Defaults to `"round"`.
6365
*/
64-
@Prop() shape?: 'soft' | 'round' | 'rectangular';
66+
@Prop() shape?: IonChipShape;
6567

6668
// TODO(FW-6266): Determine if `medium` size is needed.
6769
/**
6870
* Set to `"small"` for a chip with less height and padding.
6971
*
7072
* Defaults to `"large"`.
7173
*/
72-
@Prop() size?: 'small' | 'large';
74+
@Prop() size?: IonChipSize;
7375

7476
componentDidLoad() {
7577
if (this.outline) {

0 commit comments

Comments
 (0)