Skip to content

Commit 83c2d1c

Browse files
refactor(disabled): add disabled prop to lib/input, use centrally defined disabled classs
1 parent e031239 commit 83c2d1c

16 files changed

+50
-25
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const classesDisabledDirectly = "cursor-not-allowed opacity-70"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const classesDisabledModifier = "disabled:cursor-not-allowed disabled:opacity-70"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const classesDisabledModifierPeer = "peer-disabled:cursor-not-allowed peer-disabled:opacity-70"

lib/input/check/CheckMultiple.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { HasValueSignalStringArray } from "~ui/utils/HasValueSignalStringAr
1111
import type { MayHaveValueText } from "~ui/utils/HasValueText"
1212
import type { MayHaveButtonVariant } from "~ui/utils/MayHaveButtonVariant"
1313
import type { MayHaveClass } from "~ui/utils/MayHaveClass"
14+
import type { MayHaveDisabled } from "~ui/utils/MayHaveDisabled"
1415
import type { MayHaveId } from "~ui/utils/MayHaveId"
1516
import type { MayHaveInnerClass } from "~ui/utils/MayHaveInnerClass"
1617

@@ -21,7 +22,8 @@ export interface CheckMultipleProps
2122
MayHaveId,
2223
MayHaveButtonVariant,
2324
MayHaveClass,
24-
MayHaveInnerClass {
25+
MayHaveInnerClass,
26+
MayHaveDisabled {
2527
// styling
2628
optionClass?: string
2729
}
@@ -57,7 +59,8 @@ interface OptionListProps
5759
HasGetOptions,
5860
MayHaveValueText,
5961
MayHaveButtonVariant,
60-
MayHaveInnerClass {
62+
MayHaveInnerClass,
63+
MayHaveDisabled {
6164
optionClass?: string
6265
}
6366

@@ -72,14 +75,15 @@ function OptionList(p: OptionListProps) {
7275
valueText={p.valueText}
7376
optionClass={p.optionClass}
7477
variant={p.variant}
78+
disabled={p.disabled}
7579
/>
7680
)}
7781
</For>
7882
</div>
7983
)
8084
}
8185

82-
interface CheckOptionProps extends MayHaveButtonVariant {
86+
interface CheckOptionProps extends MayHaveButtonVariant, MayHaveDisabled {
8387
option: string
8488
valueSignal: SignalObject<string[]>
8589
valueText?: (value: string) => string
@@ -99,6 +103,7 @@ function CheckOption(p: CheckOptionProps) {
99103
onClick={() => toggleOption(p)}
100104
variant={p.variant ?? buttonVariant.filled}
101105
class={classMerge("justify-start text-left", p.optionClass)}
106+
disabled={p.disabled}
102107
>
103108
{label()}
104109
</ButtonIcon>

lib/input/check/Checkbox.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { mdiCheckboxBlankOutline, mdiCheckboxMarked } from "@mdi/js"
22
import { splitProps, type ComponentProps } from "solid-js"
3+
import { classesDisabledDirectly } from "~ui/classes/classesDisabledDirectly"
34
import { Icon1 } from "~ui/static/icon/Icon1"
45
import type { MayHaveChildren } from "~ui/utils/MayHaveChildren"
56
import type { MayHaveClass } from "~ui/utils/MayHaveClass"
7+
import type { MayHaveDisabled } from "~ui/utils/MayHaveDisabled"
68
import { classMerge } from "~ui/utils/classMerge"
79

8-
interface CheckboxProps extends MayHaveClass, MayHaveChildren, ComponentProps<"checkbox"> {
10+
interface CheckboxProps extends MayHaveClass, MayHaveChildren, MayHaveDisabled, ComponentProps<"checkbox"> {
911
id?: string
1012
checked: boolean
1113
onChange: (checked: boolean) => void
12-
disabled?: boolean
1314
}
1415

1516
export function Checkbox(p: CheckboxProps) {
@@ -37,7 +38,7 @@ export function Checkbox(p: CheckboxProps) {
3738
"size-6", // sizing + interaction
3839
"cursor-pointer", // cursor
3940
"flex items-center justify-center", // layout children
40-
s.disabled && "cursor-not-allowed opacity-50", // disabled state
41+
s.disabled && classesDisabledDirectly, // disabled state
4142
)}
4243
role="checkbox"
4344
aria-checked={s.checked}
@@ -57,7 +58,7 @@ export function Checkbox(p: CheckboxProps) {
5758
for={s.id}
5859
class={classMerge(
5960
"cursor-pointer", // interaction
60-
s.disabled && "cursor-not-allowed opacity-70", // disabled state
61+
s.disabled && classesDisabledDirectly, // disabled state
6162
)}
6263
onClick={(e) => {
6364
e.preventDefault()

lib/input/input/Input.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Component, ComponentProps } from "solid-js"
22
import { splitProps } from "solid-js"
3+
import { classesDisabledModifier } from "~ui/classes/classesDisabledModifier"
34
import { classMerge } from "~ui/utils/classMerge"
45

56
export const Input: Component<ComponentProps<"input">> = (p) => {
@@ -17,7 +18,7 @@ export const Input: Component<ComponentProps<"input">> = (p) => {
1718
"placeholder:text-muted-foreground", // typography
1819
"file:border-0 file:bg-transparent file:font-medium", // file input styling
1920
"focus-visible:ring-ring focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-offset-2", // focus states
20-
"disabled:cursor-not-allowed disabled:opacity-50", // disabled states
21+
classesDisabledModifier, // disabled
2122
s.class,
2223
)}
2324
dir="auto"

lib/input/label/Label.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Component, ComponentProps } from "solid-js"
22
import { splitProps } from "solid-js"
3+
import { classesDisabledModifierPeer } from "~ui/classes/classesDisabledModifierPeer"
34
import { classMerge } from "~ui/utils/classMerge"
45

56
export const Label: Component<ComponentProps<"label">> = (p) => {
@@ -9,7 +10,7 @@ export const Label: Component<ComponentProps<"label">> = (p) => {
910
class={classMerge(
1011
"font-medium leading-none", // font
1112
"whitespace-nowrap", // no text wrapping
12-
"peer-disabled:cursor-not-allowed peer-disabled:opacity-70", // disabled
13+
classesDisabledModifierPeer, // disabled
1314
s.class,
1415
)}
1516
{...rest}

lib/input/select/SelectMultiple.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { HasValueSignalStringArray } from "~ui/utils/HasValueSignalStringAr
1616
import type { MayHaveValueText } from "~ui/utils/HasValueText"
1717
import type { MayHaveChildren } from "~ui/utils/MayHaveChildren"
1818
import type { MayHaveClass } from "~ui/utils/MayHaveClass"
19+
import type { MayHaveDisabled } from "~ui/utils/MayHaveDisabled"
1920
import type { MayHaveId } from "~ui/utils/MayHaveId"
2021
import type { MayHaveInnerClass } from "~ui/utils/MayHaveInnerClass"
2122

@@ -29,7 +30,8 @@ export interface SelectMultipleProps
2930
MayHaveId,
3031
MayHaveClass,
3132
MayHaveInnerClass,
32-
MayHaveChildren {
33+
MayHaveChildren,
34+
MayHaveDisabled {
3335
buttonProps: CorvuPopoverProps
3436
textNoEntries?: string
3537
textAddEntry?: string
@@ -44,6 +46,7 @@ export function SelectMultiple(p: SelectMultipleProps) {
4446
icon: mdiPlus,
4547
children: p.textAddEntry ?? ct0(t4multiselect.Add_entry),
4648
class: buttonClass,
49+
disabled: p.disabled,
4750
})
4851
return (
4952
<div
@@ -68,6 +71,7 @@ export function SelectMultiple(p: SelectMultipleProps) {
6871
noItemsClass={p.noItemsClass}
6972
listOptionClass={p.listOptionClass}
7073
innerClass={p.innerClass}
74+
disabled={p.disabled}
7175
/>
7276
</CorvuPopover>
7377
</div>
@@ -121,7 +125,8 @@ interface OptionListProps
121125
HasGetOptions,
122126
MayHaveValueText,
123127
MayHaveId,
124-
MayHaveInnerClass {
128+
MayHaveInnerClass,
129+
MayHaveDisabled {
125130
noItemsClass?: string
126131
listOptionClass?: string
127132
}
@@ -138,6 +143,7 @@ function OptionList(p: OptionListProps) {
138143
valueSignal={p.valueSignal}
139144
valueText={p.valueText}
140145
listOptionClass={p.listOptionClass}
146+
disabled={p.disabled}
141147
/>
142148
)}
143149
</For>
@@ -155,7 +161,7 @@ function getInnerClass(optionAmount: number, innerClass?: string): string {
155161
return ""
156162
}
157163

158-
interface ListOptionProps extends MayHaveId, MultiselectOptionState {
164+
interface ListOptionProps extends MayHaveId, MultiselectOptionState, MayHaveDisabled {
159165
index: number
160166
listOptionClass?: string
161167
}
@@ -173,6 +179,7 @@ function ListOption(p: ListOptionProps) {
173179
}}
174180
variant={buttonVariant.ghost}
175181
class={classMerge("justify-start", p.listOptionClass)}
182+
disabled={p.disabled}
176183
>
177184
{label()}
178185
</ButtonIcon>

lib/input/select/SelectSingleNative.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { Key } from "@solid-primitives/keyed"
2+
import { classesDisabledDirectly } from "~ui/classes/classesDisabledDirectly"
23
import { ct0 } from "~ui/i18n/ct0"
34
import { t4multiselect } from "~ui/input/select/t4multiselect"
45
import type { HasGetOptions } from "~ui/utils/HasGetOptions"
56
import type { HasValueSignalString } from "~ui/utils/HasValueSignalString"
67
import type { MayHaveValueText } from "~ui/utils/HasValueText"
78
import type { MayHaveChildren } from "~ui/utils/MayHaveChildren"
89
import type { MayHaveClass } from "~ui/utils/MayHaveClass"
10+
import type { MayHaveDisabled } from "~ui/utils/MayHaveDisabled"
911
import type { MayHaveId } from "~ui/utils/MayHaveId"
1012
import { classArr } from "~ui/utils/classArr"
1113

@@ -17,7 +19,8 @@ export interface SelectSingleNativeProps
1719
MayHaveValueText,
1820
MayHaveClass,
1921
MayHaveId,
20-
MayHaveChildren {}
22+
MayHaveChildren,
23+
MayHaveDisabled {}
2124

2225
export function SelectSingleNative(p: SelectSingleNativeProps) {
2326
return (
@@ -30,10 +33,12 @@ export function SelectSingleNative(p: SelectSingleNativeProps) {
3033
"bg-gray-50 dark:bg-gray-700", // bg
3134
"rounded-lg border border-gray-300 dark:border-gray-500", // border
3235
"focus:ring-blue-500 focus:border-blue-500 dark:focus:border-blue-500 dark:focus:ring-blue-500",
36+
p.disabled && classesDisabledDirectly,
3337
p.class,
3438
)}
3539
value={p.valueSignal.get()}
3640
onChange={(e) => onChange(e, p)}
41+
disabled={p.disabled}
3742
>
3843
<Key each={p.getOptions()} by={(item) => item} fallback={<NoItems />}>
3944
{(getItem) => <SelectItem itemValue={getItem()} valueText={p.valueText} />}

lib/input/textarea/Textarea.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Component, ComponentProps } from "solid-js"
22
import { splitProps } from "solid-js"
3+
import { classesDisabledModifier } from "~ui/classes/classesDisabledModifier"
34
import { classMerge } from "~ui/utils/classMerge"
45

56
export const Textarea: Component<ComponentProps<"textarea">> = (p) => {
@@ -15,7 +16,7 @@ export const Textarea: Component<ComponentProps<"textarea">> = (p) => {
1516
"placeholder:text-muted-foreground", // typography
1617
"px-3 py-2", // spacing
1718
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2 ring-offset-background", // focus states
18-
"disabled:cursor-not-allowed disabled:opacity-50", // disabled states
19+
classesDisabledModifier, // disabled
1920
s.class,
2021
)}
2122
{...rest}

0 commit comments

Comments
 (0)