Skip to content

Commit fc8dbea

Browse files
committed
fix: centralize checkbox icons prop
1 parent 8b0474e commit fc8dbea

File tree

5 files changed

+74
-33
lines changed

5 files changed

+74
-33
lines changed

packages/components/src/components/input-checkbox/controller.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import type {
22
CheckedPropType,
33
IndeterminatePropType,
44
InputCheckboxIconsProp,
5+
InputCheckboxIconsPropType,
56
InputCheckboxIconsState,
67
InputCheckboxProps,
78
InputCheckboxVariantPropType,
89
InputCheckboxWatches,
910
LabelAlignPropType,
1011
StencilUnknown,
11-
Stringified,
1212
} from '../../schema';
1313
import { isString, setState, validateChecked, validateIndeterminate, validateLabelAlign, validateVariantInputCheckbox, watchValidator } from '../../schema';
1414

@@ -36,15 +36,16 @@ export class InputCheckboxController extends InputCheckboxRadioController implem
3636
this.setFormAssociatedCheckboxValue(this.component.state._value as StencilUnknown);
3737
}
3838

39-
public validateIcons(value?: Stringified<InputCheckboxIconsProp>): void {
40-
watchValidator(
39+
public validateIcons(value?: InputCheckboxIconsPropType): void {
40+
watchValidator<unknown>(
4141
this.component,
4242
'_icons',
43-
(value?: Record<string, unknown>): boolean => {
44-
return typeof value === 'object' && value !== null && (isString(value.checked, 1) || isString(value.indeterminate, 1) || isString(value.unchecked, 1));
43+
(value): boolean => {
44+
const v = value as Record<string, unknown>;
45+
return typeof v === 'object' && v !== null && (isString(v.checked, 1) || isString(v.indeterminate, 1) || isString(v.unchecked, 1));
4546
},
4647
new Set(['InputCheckboxIcons']),
47-
value,
48+
value as unknown,
4849
{
4950
hooks: {
5051
beforePatch: (nextValue: unknown, nextState: Map<string, unknown>, component: Generic.Element.Component) => {

packages/components/src/components/input-date/controller.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,13 @@ export class InputDateController extends InputIconController implements InputDat
132132
return watchValidator(
133133
this.component,
134134
propName,
135-
(value: unknown): boolean => value === undefined || value === null || value === '' || this.validateDateString(value),
135+
(value): boolean => value === undefined || value === null || value === '' || this.validateDateString(value),
136136
new Set(['Date', 'string{ISO-8601}']),
137137
InputDateController.tryParseToString(value, this.component._type, this.component._step),
138138
{
139139
hooks: {
140-
afterPatch: (value: string) => {
140+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
141+
afterPatch: (value: unknown, _state: Record<string, unknown>, _component: Generic.Element.Component, _key: string): void => {
141142
if (typeof value === 'string' && afterPatch) {
142143
afterPatch(value);
143144
}

packages/components/src/schema/components/input-checkbox.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
PropHideLabel,
88
PropHideMsg,
99
PropHint,
10+
PropIconsInputCheckbox,
1011
PropIndeterminate,
1112
PropLabelAlign,
1213
PropLabelWithExpertSlot,
@@ -17,42 +18,20 @@ import type {
1718
PropSyncValueBySelector,
1819
PropTouched,
1920
PropVariantInputCheckbox,
21+
InputCheckboxIconsState,
2022
} from '../props';
21-
import type { AnyIconFontClass, InputTypeOnDefault, StencilUnknown, Stringified } from '../types';
22-
23-
export type InputCheckboxIconsProp =
24-
| {
25-
checked: AnyIconFontClass;
26-
indeterminate?: AnyIconFontClass;
27-
unchecked?: AnyIconFontClass;
28-
}
29-
| {
30-
checked?: AnyIconFontClass;
31-
indeterminate: AnyIconFontClass;
32-
unchecked?: AnyIconFontClass;
33-
}
34-
| {
35-
checked?: AnyIconFontClass;
36-
indeterminate?: AnyIconFontClass;
37-
unchecked: AnyIconFontClass;
38-
};
39-
40-
export type InputCheckboxIconsState = {
41-
checked: AnyIconFontClass;
42-
indeterminate: AnyIconFontClass;
43-
unchecked: AnyIconFontClass;
44-
};
23+
import type { InputTypeOnDefault, StencilUnknown } from '../types';
4524

4625
type RequiredProps = PropLabelWithExpertSlot;
4726
type OptionalProps = {
48-
icons: Stringified<InputCheckboxIconsProp>;
4927
on: InputTypeOnDefault;
5028
value: StencilUnknown;
5129
} & PropAccessKey &
5230
PropChecked &
5331
PropDisabled &
5432
PropHideMsg &
5533
PropHideLabel &
34+
PropIconsInputCheckbox &
5635
PropIndeterminate &
5736
PropName &
5837
PropRequired &
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import type { Generic } from 'adopted-style-sheets';
2+
3+
import type { AnyIconFontClass, Stringified } from '../types';
4+
import { isString } from '../validators';
5+
import { watchValidator } from '../utils';
6+
7+
export type InputCheckboxIconsProp =
8+
| {
9+
checked: AnyIconFontClass;
10+
indeterminate?: AnyIconFontClass;
11+
unchecked?: AnyIconFontClass;
12+
}
13+
| {
14+
checked?: AnyIconFontClass;
15+
indeterminate: AnyIconFontClass;
16+
unchecked?: AnyIconFontClass;
17+
}
18+
| {
19+
checked?: AnyIconFontClass;
20+
indeterminate?: AnyIconFontClass;
21+
unchecked: AnyIconFontClass;
22+
};
23+
24+
export type InputCheckboxIconsState = {
25+
checked: AnyIconFontClass;
26+
indeterminate: AnyIconFontClass;
27+
unchecked: AnyIconFontClass;
28+
};
29+
30+
export type InputCheckboxIconsPropType = Stringified<InputCheckboxIconsProp>;
31+
32+
export type PropIconsInputCheckbox = {
33+
icons: InputCheckboxIconsPropType;
34+
};
35+
36+
export const validateIconsInputCheckbox = (component: Generic.Element.Component, value?: InputCheckboxIconsPropType): void => {
37+
watchValidator<unknown>(
38+
component,
39+
'_icons',
40+
(value): boolean =>
41+
typeof value === 'object' &&
42+
value !== null &&
43+
(isString((value as Record<string, unknown>).checked, 1) ||
44+
isString((value as Record<string, unknown>).indeterminate, 1) ||
45+
isString((value as Record<string, unknown>).unchecked, 1)),
46+
new Set(['InputCheckboxIcons']),
47+
value as unknown,
48+
{
49+
hooks: {
50+
beforePatch: (nextValue: unknown, nextState: Map<string, unknown>, component: Generic.Element.Component) => {
51+
nextState.set('_icons', {
52+
...(component.state._icons as InputCheckboxIconsState),
53+
...(nextValue as InputCheckboxIconsProp),
54+
});
55+
},
56+
},
57+
},
58+
);
59+
};

packages/components/src/schema/props/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export * from './hide-msg';
3636
export * from './hint';
3737
export * from './href';
3838
export * from './icons';
39+
export * from './icons-input-checkbox';
3940
export * from './id';
4041
export * from './image-source';
4142
export * from './image-sizes';

0 commit comments

Comments
 (0)