Skip to content

Commit de499aa

Browse files
authored
[♻️]: Refactor to rename indeterminated to indeterminate (#99)
* Refactor to rename `indeterminated` to `indeterminate` * Update version
1 parent b56ed40 commit de499aa

File tree

5 files changed

+40
-38
lines changed

5 files changed

+40
-38
lines changed

lib/Checkbox/Checkbox.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ describe("Checkbox", () => {
4141
disabled,
4242
readOnly,
4343
focusedVisible,
44-
indeterminated,
44+
indeterminate,
4545
}) =>
4646
classNames("root", {
4747
"root--disabled": disabled,
4848
"root--readonly": readOnly,
4949
"root--checked": checked,
5050
"root--focus-visible": focusedVisible,
51-
"root--indeterminated": indeterminated,
51+
"root--indeterminate": indeterminate,
5252
})
5353
}
5454
/>,
@@ -73,14 +73,14 @@ describe("Checkbox", () => {
7373
disabled,
7474
readOnly,
7575
focusedVisible,
76-
indeterminated,
76+
indeterminate,
7777
}) =>
7878
classNames("root", {
7979
"root--disabled": disabled,
8080
"root--readonly": readOnly,
8181
"root--checked": checked,
8282
"root--focus-visible": focusedVisible,
83-
"root--indeterminated": indeterminated,
83+
"root--indeterminate": indeterminate,
8484
})
8585
}
8686
/>,
@@ -96,29 +96,29 @@ describe("Checkbox", () => {
9696
rerender(
9797
<Checkbox
9898
{...mockRequiredProps}
99-
checked="indeterminated"
99+
checked="indeterminate"
100100
aria-controls="id1"
101101
className={({
102102
checked,
103103
disabled,
104104
readOnly,
105105
focusedVisible,
106-
indeterminated,
106+
indeterminate,
107107
}) =>
108108
classNames("root", {
109109
"root--disabled": disabled,
110110
"root--readonly": readOnly,
111111
"root--checked": checked,
112112
"root--focus-visible": focusedVisible,
113-
"root--indeterminated": indeterminated,
113+
"root--indeterminate": indeterminate,
114114
})
115115
}
116116
/>,
117117
);
118118

119119
expect(screen.getByRole("checkbox")).toHaveClass(
120120
"root",
121-
"root--indeterminated",
121+
"root--indeterminate",
122122
);
123123
});
124124

@@ -150,7 +150,7 @@ describe("Checkbox", () => {
150150
render(
151151
<Checkbox
152152
{...mockRequiredProps}
153-
defaultChecked="indeterminated"
153+
defaultChecked="indeterminate"
154154
aria-controls="id1 id2"
155155
/>,
156156
);

lib/Checkbox/Checkbox.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export type RenderProps = {
2929
*/
3030
disabled: boolean;
3131
/**
32-
* The `indeterminated` state of the checkbox.
32+
* The `indeterminate` state of the checkbox.
3333
*/
34-
indeterminated: boolean;
34+
indeterminate: boolean;
3535
/**
3636
* The `:focus-visible` of the checkbox.
3737
*/
@@ -85,18 +85,18 @@ type OwnProps = {
8585
/**
8686
* If `true`, the checkbox will be checked.
8787
*
88-
* If `indeterminated`, the checkbox will appear indeterminate.
88+
* If `indeterminate`, the checkbox will appear indeterminate.
8989
* This does not set the native input element to indeterminate due to inconsistent behavior across browsers.
9090
*
9191
* @default false
9292
*/
93-
checked?: boolean | "indeterminated";
93+
checked?: boolean | "indeterminate";
9494
/**
9595
* The default state of `checked`. Use when the component is not controlled.
9696
*
9797
* @default false
9898
*/
99-
defaultChecked?: boolean | "indeterminated";
99+
defaultChecked?: boolean | "indeterminate";
100100
/**
101101
* If `true`, the checkbox will be disabled.
102102
*
@@ -231,13 +231,13 @@ const CheckboxBase = (props: Props, ref: React.Ref<HTMLButtonElement>) => {
231231
].join("\n"),
232232
});
233233

234-
const isIndeterminated = checkBase.checked === "indeterminated";
234+
const isIndeterminated = checkBase.checked === "indeterminate";
235235
const isChecked = isIndeterminated ? false : (checkBase.checked as boolean);
236236

237237
const renderProps: RenderProps = {
238238
disabled: isDisabled,
239239
readOnly: isReadOnly,
240-
indeterminated: isIndeterminated,
240+
indeterminate: isIndeterminated,
241241
checked: isChecked,
242242
focusedVisible: checkBase.isFocusedVisible,
243243
};
@@ -268,7 +268,7 @@ const CheckboxBase = (props: Props, ref: React.Ref<HTMLButtonElement>) => {
268268
"data-slot": Slots.Root,
269269
"data-disabled": isDisabled ? "" : undefined,
270270
"data-readonly": isReadOnly ? "" : undefined,
271-
"data-indeterminated": isIndeterminated ? "" : undefined,
271+
"data-indeterminate": isIndeterminated ? "" : undefined,
272272
"data-focus-visible": checkBase.isFocusedVisible ? "" : undefined,
273273
"data-checked": isChecked ? "" : undefined,
274274
};

lib/ProgressBar/ProgressBar.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export type RenderProps = {
1818
*/
1919
valueText: string;
2020
/**
21-
* Determines whether the progress bar is indeterminated or not.
21+
* Determines whether the progress bar is indeterminate or not.
2222
*/
23-
indeterminated: boolean;
23+
indeterminate: boolean;
2424
};
2525

2626
export type ClassNameProps = RenderProps;
@@ -37,7 +37,7 @@ type OwnProps = {
3737
/**
3838
* The current value of the progress bar.
3939
*/
40-
value: number;
40+
value: number | "indeterminate";
4141
/**
4242
* The minimum allowed value of the progress bar.
4343
* Should not be greater than or equal to `max`.
@@ -52,14 +52,11 @@ type OwnProps = {
5252
* A string value that provides a user-friendly name
5353
* for the current value of the progress bar.
5454
* This is important for screen reader users.
55-
*/
56-
valueText: string;
57-
/**
58-
* If `true`, the progress bar value will be indeterminate.
5955
*
60-
* @default false;
56+
* If component is indeterminate, it ignores valuetext
57+
* since we don't have any deterministic value.
6158
*/
62-
indeterminated?: boolean;
59+
valueText: string;
6360
/**
6461
* The label of the component.
6562
*/
@@ -89,7 +86,6 @@ const ProgressBarBase = (props: Props, ref: React.Ref<HTMLDivElement>) => {
8986
const {
9087
className: classNameProp,
9188
children: childrenProp,
92-
indeterminated = false,
9389
value,
9490
min,
9591
max,
@@ -106,13 +102,19 @@ const ProgressBarBase = (props: Props, ref: React.Ref<HTMLDivElement>) => {
106102
].join("\n"),
107103
});
108104

109-
const percentageValue = remap(value, min, max, 0, 100);
105+
const isIndeterminate = value === "indeterminate";
106+
107+
const numericValue = isIndeterminate ? min : value;
108+
109+
const percentageValue = isIndeterminate
110+
? min
111+
: remap(numericValue, min, max, 0, 100);
110112

111113
const renderProps: RenderProps = {
112114
percentageValue,
113-
value,
115+
value: numericValue,
114116
valueText,
115-
indeterminated,
117+
indeterminate: isIndeterminate,
116118
};
117119

118120
const classNameProps: ClassNameProps = renderProps;
@@ -126,14 +128,14 @@ const ProgressBarBase = (props: Props, ref: React.Ref<HTMLDivElement>) => {
126128
role="progressbar"
127129
ref={ref}
128130
className={className}
129-
aria-valuenow={indeterminated ? undefined : value}
131+
aria-valuenow={isIndeterminate ? undefined : value}
130132
aria-valuemin={min}
131133
aria-valuemax={max}
132-
aria-valuetext={indeterminated ? undefined : valueText}
134+
aria-valuetext={isIndeterminate ? undefined : valueText}
133135
aria-label={labelInfo.srOnlyLabel}
134136
aria-labelledby={labelInfo.labelledBy}
135137
data-slot={RootSlot}
136-
data-indeterminated={indeterminated ? "" : undefined}
138+
data-indeterminate={isIndeterminate ? "" : undefined}
137139
>
138140
{children}
139141
</div>

lib/utils/use-check-base.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ type CheckBaseProps = {
2121
keyboardActivationBehavior?: "manual" | "automatic";
2222
value?: string;
2323
groupCtx: GenericGroupContextValue | null;
24-
checked?: boolean | "indeterminated";
25-
defaultChecked?: boolean | "indeterminated";
24+
checked?: boolean | "indeterminate";
25+
defaultChecked?: boolean | "indeterminate";
2626
togglable?: boolean;
2727
disabled?: boolean;
2828
readOnly?: boolean;
@@ -122,7 +122,7 @@ const useCheckBase = (props: CheckBaseProps) => {
122122
event.preventDefault();
123123

124124
const newChecked =
125-
checkedState === "indeterminated" ? true : !checkedState;
125+
checkedState === "indeterminate" ? true : !checkedState;
126126

127127
emitChange(newChecked);
128128
},
@@ -293,7 +293,7 @@ const useCheckBase = (props: CheckBaseProps) => {
293293
}
294294

295295
const newChecked =
296-
checkedState === "indeterminated" ? true : !checkedState;
296+
checkedState === "indeterminate" ? true : !checkedState;
297297

298298
if (event.key === SystemKeys.SPACE) {
299299
emitChange(newChecked);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@styleless-ui/react",
3-
"version": "1.0.0-rc.6",
3+
"version": "1.0.0-rc.7",
44
"description": "Completely unstyled, headless and accessible React UI components.",
55
"author": "mimshins <mostafa.sh.coderino@gmail.com>",
66
"license": "MIT",

0 commit comments

Comments
 (0)