@maratus-registry/boolean-control 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css-files/BooleanControl.tsx +9 -0
- package/css-files/BooleanControl.types.ts +54 -0
- package/css-files/index.ts +10 -0
- package/css-files/useBooleanControl.ts +58 -0
- package/css-modules/BooleanControl.tsx +9 -0
- package/css-modules/BooleanControl.types.ts +54 -0
- package/css-modules/index.ts +10 -0
- package/css-modules/useBooleanControl.ts +58 -0
- package/meta.json +5 -0
- package/package.json +19 -4
- package/tailwind-css/BooleanControl.tsx +9 -0
- package/tailwind-css/BooleanControl.types.ts +54 -0
- package/tailwind-css/index.ts +10 -0
- package/tailwind-css/useBooleanControl.ts +58 -0
- package/README.md +0 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BooleanControlProps } from './BooleanControl.types'
|
|
2
|
+
import { useBooleanControl } from './useBooleanControl'
|
|
3
|
+
|
|
4
|
+
export function BooleanControl(props: BooleanControlProps) {
|
|
5
|
+
const { children, ...hookProps } = props
|
|
6
|
+
const control = useBooleanControl(hookProps)
|
|
7
|
+
|
|
8
|
+
return children(control)
|
|
9
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FieldControlRenderProps,
|
|
3
|
+
ValidityHandlerProps,
|
|
4
|
+
} from '@maratus-component/field'
|
|
5
|
+
import type { AriaAttributes, ReactNode } from 'react'
|
|
6
|
+
|
|
7
|
+
export type BooleanControlRole = 'checkbox' | 'switch'
|
|
8
|
+
|
|
9
|
+
export type BooleanControlRenderProps = FieldControlRenderProps &
|
|
10
|
+
ValidityHandlerProps & {
|
|
11
|
+
'aria-checked'?: AriaAttributes['aria-checked']
|
|
12
|
+
checked?: boolean
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
name?: string
|
|
15
|
+
required?: boolean
|
|
16
|
+
role?: BooleanControlRole
|
|
17
|
+
type?: 'checkbox'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type BooleanControlRenderArgs = {
|
|
21
|
+
booleanControlProps: BooleanControlRenderProps
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type UseBooleanControlOptions = Omit<
|
|
25
|
+
BooleanControlRenderProps,
|
|
26
|
+
| 'aria-busy'
|
|
27
|
+
| 'aria-checked'
|
|
28
|
+
| 'aria-describedby'
|
|
29
|
+
| 'aria-disabled'
|
|
30
|
+
| 'aria-errormessage'
|
|
31
|
+
| 'aria-invalid'
|
|
32
|
+
| 'aria-readonly'
|
|
33
|
+
| 'aria-required'
|
|
34
|
+
| 'children'
|
|
35
|
+
| 'data-loading'
|
|
36
|
+
| 'disabled'
|
|
37
|
+
| 'id'
|
|
38
|
+
| 'name'
|
|
39
|
+
| 'required'
|
|
40
|
+
| 'role'
|
|
41
|
+
| 'type'
|
|
42
|
+
| keyof ValidityHandlerProps
|
|
43
|
+
> &
|
|
44
|
+
Partial<ValidityHandlerProps> & {
|
|
45
|
+
role?: BooleanControlRole
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type UseBooleanControlResult = {
|
|
49
|
+
booleanControlProps: BooleanControlRenderProps
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type BooleanControlProps = UseBooleanControlOptions & {
|
|
53
|
+
children: (props: BooleanControlRenderArgs) => ReactNode
|
|
54
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
BooleanControlProps,
|
|
3
|
+
BooleanControlRenderArgs,
|
|
4
|
+
BooleanControlRenderProps,
|
|
5
|
+
BooleanControlRole,
|
|
6
|
+
UseBooleanControlOptions,
|
|
7
|
+
UseBooleanControlResult,
|
|
8
|
+
} from './BooleanControl.types'
|
|
9
|
+
export { BooleanControl } from './BooleanControl'
|
|
10
|
+
export { useBooleanControl } from './useBooleanControl'
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BooleanControlRenderProps,
|
|
3
|
+
UseBooleanControlOptions,
|
|
4
|
+
UseBooleanControlResult,
|
|
5
|
+
} from './BooleanControl.types'
|
|
6
|
+
import type {
|
|
7
|
+
FieldContextValue,
|
|
8
|
+
FieldControlRenderProps,
|
|
9
|
+
ValidityHandlerProps,
|
|
10
|
+
} from '@maratus-component/field'
|
|
11
|
+
import { useFieldContext, useFieldControl } from '@maratus-component/field'
|
|
12
|
+
import { mergeRefs } from '@maratus-lib/props'
|
|
13
|
+
|
|
14
|
+
export function useBooleanControl(
|
|
15
|
+
options: UseBooleanControlOptions = {},
|
|
16
|
+
): UseBooleanControlResult {
|
|
17
|
+
const { role, ...fieldControlOptions } = options
|
|
18
|
+
const field = useFieldContext('BooleanControl')
|
|
19
|
+
const { fieldControlProps, validityHandlerProps } =
|
|
20
|
+
useFieldControl(fieldControlOptions)
|
|
21
|
+
const controlProps = {
|
|
22
|
+
...fieldControlProps,
|
|
23
|
+
...validityHandlerProps,
|
|
24
|
+
ref: mergeRefs(fieldControlProps.ref, validityHandlerProps.ref),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (role) {
|
|
28
|
+
return {
|
|
29
|
+
booleanControlProps: {
|
|
30
|
+
...controlProps,
|
|
31
|
+
...(field.isRequired ? { 'aria-required': true } : {}),
|
|
32
|
+
role,
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
booleanControlProps: getNativeBooleanControlProps(controlProps, field),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getNativeBooleanControlProps(
|
|
43
|
+
fieldControlProps: FieldControlRenderProps & ValidityHandlerProps,
|
|
44
|
+
field: FieldContextValue,
|
|
45
|
+
): BooleanControlRenderProps {
|
|
46
|
+
const booleanControlProps = { ...fieldControlProps }
|
|
47
|
+
|
|
48
|
+
delete booleanControlProps['aria-readonly']
|
|
49
|
+
delete booleanControlProps['aria-required']
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
...booleanControlProps,
|
|
53
|
+
...(field.isLoading ? { disabled: true } : {}),
|
|
54
|
+
name: field.name,
|
|
55
|
+
...(field.isRequired ? { required: true } : {}),
|
|
56
|
+
type: 'checkbox',
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BooleanControlProps } from './BooleanControl.types'
|
|
2
|
+
import { useBooleanControl } from './useBooleanControl'
|
|
3
|
+
|
|
4
|
+
export function BooleanControl(props: BooleanControlProps) {
|
|
5
|
+
const { children, ...hookProps } = props
|
|
6
|
+
const control = useBooleanControl(hookProps)
|
|
7
|
+
|
|
8
|
+
return children(control)
|
|
9
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FieldControlRenderProps,
|
|
3
|
+
ValidityHandlerProps,
|
|
4
|
+
} from '@maratus-component/field'
|
|
5
|
+
import type { AriaAttributes, ReactNode } from 'react'
|
|
6
|
+
|
|
7
|
+
export type BooleanControlRole = 'checkbox' | 'switch'
|
|
8
|
+
|
|
9
|
+
export type BooleanControlRenderProps = FieldControlRenderProps &
|
|
10
|
+
ValidityHandlerProps & {
|
|
11
|
+
'aria-checked'?: AriaAttributes['aria-checked']
|
|
12
|
+
checked?: boolean
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
name?: string
|
|
15
|
+
required?: boolean
|
|
16
|
+
role?: BooleanControlRole
|
|
17
|
+
type?: 'checkbox'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type BooleanControlRenderArgs = {
|
|
21
|
+
booleanControlProps: BooleanControlRenderProps
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type UseBooleanControlOptions = Omit<
|
|
25
|
+
BooleanControlRenderProps,
|
|
26
|
+
| 'aria-busy'
|
|
27
|
+
| 'aria-checked'
|
|
28
|
+
| 'aria-describedby'
|
|
29
|
+
| 'aria-disabled'
|
|
30
|
+
| 'aria-errormessage'
|
|
31
|
+
| 'aria-invalid'
|
|
32
|
+
| 'aria-readonly'
|
|
33
|
+
| 'aria-required'
|
|
34
|
+
| 'children'
|
|
35
|
+
| 'data-loading'
|
|
36
|
+
| 'disabled'
|
|
37
|
+
| 'id'
|
|
38
|
+
| 'name'
|
|
39
|
+
| 'required'
|
|
40
|
+
| 'role'
|
|
41
|
+
| 'type'
|
|
42
|
+
| keyof ValidityHandlerProps
|
|
43
|
+
> &
|
|
44
|
+
Partial<ValidityHandlerProps> & {
|
|
45
|
+
role?: BooleanControlRole
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type UseBooleanControlResult = {
|
|
49
|
+
booleanControlProps: BooleanControlRenderProps
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type BooleanControlProps = UseBooleanControlOptions & {
|
|
53
|
+
children: (props: BooleanControlRenderArgs) => ReactNode
|
|
54
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
BooleanControlProps,
|
|
3
|
+
BooleanControlRenderArgs,
|
|
4
|
+
BooleanControlRenderProps,
|
|
5
|
+
BooleanControlRole,
|
|
6
|
+
UseBooleanControlOptions,
|
|
7
|
+
UseBooleanControlResult,
|
|
8
|
+
} from './BooleanControl.types'
|
|
9
|
+
export { BooleanControl } from './BooleanControl'
|
|
10
|
+
export { useBooleanControl } from './useBooleanControl'
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BooleanControlRenderProps,
|
|
3
|
+
UseBooleanControlOptions,
|
|
4
|
+
UseBooleanControlResult,
|
|
5
|
+
} from './BooleanControl.types'
|
|
6
|
+
import type {
|
|
7
|
+
FieldContextValue,
|
|
8
|
+
FieldControlRenderProps,
|
|
9
|
+
ValidityHandlerProps,
|
|
10
|
+
} from '@maratus-component/field'
|
|
11
|
+
import { useFieldContext, useFieldControl } from '@maratus-component/field'
|
|
12
|
+
import { mergeRefs } from '@maratus-lib/props'
|
|
13
|
+
|
|
14
|
+
export function useBooleanControl(
|
|
15
|
+
options: UseBooleanControlOptions = {},
|
|
16
|
+
): UseBooleanControlResult {
|
|
17
|
+
const { role, ...fieldControlOptions } = options
|
|
18
|
+
const field = useFieldContext('BooleanControl')
|
|
19
|
+
const { fieldControlProps, validityHandlerProps } =
|
|
20
|
+
useFieldControl(fieldControlOptions)
|
|
21
|
+
const controlProps = {
|
|
22
|
+
...fieldControlProps,
|
|
23
|
+
...validityHandlerProps,
|
|
24
|
+
ref: mergeRefs(fieldControlProps.ref, validityHandlerProps.ref),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (role) {
|
|
28
|
+
return {
|
|
29
|
+
booleanControlProps: {
|
|
30
|
+
...controlProps,
|
|
31
|
+
...(field.isRequired ? { 'aria-required': true } : {}),
|
|
32
|
+
role,
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
booleanControlProps: getNativeBooleanControlProps(controlProps, field),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getNativeBooleanControlProps(
|
|
43
|
+
fieldControlProps: FieldControlRenderProps & ValidityHandlerProps,
|
|
44
|
+
field: FieldContextValue,
|
|
45
|
+
): BooleanControlRenderProps {
|
|
46
|
+
const booleanControlProps = { ...fieldControlProps }
|
|
47
|
+
|
|
48
|
+
delete booleanControlProps['aria-readonly']
|
|
49
|
+
delete booleanControlProps['aria-required']
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
...booleanControlProps,
|
|
53
|
+
...(field.isLoading ? { disabled: true } : {}),
|
|
54
|
+
name: field.name,
|
|
55
|
+
...(field.isRequired ? { required: true } : {}),
|
|
56
|
+
type: 'checkbox',
|
|
57
|
+
}
|
|
58
|
+
}
|
package/meta.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maratus-registry/boolean-control",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"files": [
|
|
6
|
+
"css-files",
|
|
7
|
+
"css-modules",
|
|
8
|
+
"tailwind-css",
|
|
9
|
+
"meta.json"
|
|
10
|
+
],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@maratus-lib/props": "0.1.0",
|
|
14
|
+
"@maratus-registry/field": "0.3.0"
|
|
15
|
+
},
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"clsx": "^2.1.1",
|
|
18
|
+
"react": "^19.0.0",
|
|
19
|
+
"react-dom": "^19.0.0"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BooleanControlProps } from './BooleanControl.types'
|
|
2
|
+
import { useBooleanControl } from './useBooleanControl'
|
|
3
|
+
|
|
4
|
+
export function BooleanControl(props: BooleanControlProps) {
|
|
5
|
+
const { children, ...hookProps } = props
|
|
6
|
+
const control = useBooleanControl(hookProps)
|
|
7
|
+
|
|
8
|
+
return children(control)
|
|
9
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FieldControlRenderProps,
|
|
3
|
+
ValidityHandlerProps,
|
|
4
|
+
} from '@maratus-component/field'
|
|
5
|
+
import type { AriaAttributes, ReactNode } from 'react'
|
|
6
|
+
|
|
7
|
+
export type BooleanControlRole = 'checkbox' | 'switch'
|
|
8
|
+
|
|
9
|
+
export type BooleanControlRenderProps = FieldControlRenderProps &
|
|
10
|
+
ValidityHandlerProps & {
|
|
11
|
+
'aria-checked'?: AriaAttributes['aria-checked']
|
|
12
|
+
checked?: boolean
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
name?: string
|
|
15
|
+
required?: boolean
|
|
16
|
+
role?: BooleanControlRole
|
|
17
|
+
type?: 'checkbox'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type BooleanControlRenderArgs = {
|
|
21
|
+
booleanControlProps: BooleanControlRenderProps
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type UseBooleanControlOptions = Omit<
|
|
25
|
+
BooleanControlRenderProps,
|
|
26
|
+
| 'aria-busy'
|
|
27
|
+
| 'aria-checked'
|
|
28
|
+
| 'aria-describedby'
|
|
29
|
+
| 'aria-disabled'
|
|
30
|
+
| 'aria-errormessage'
|
|
31
|
+
| 'aria-invalid'
|
|
32
|
+
| 'aria-readonly'
|
|
33
|
+
| 'aria-required'
|
|
34
|
+
| 'children'
|
|
35
|
+
| 'data-loading'
|
|
36
|
+
| 'disabled'
|
|
37
|
+
| 'id'
|
|
38
|
+
| 'name'
|
|
39
|
+
| 'required'
|
|
40
|
+
| 'role'
|
|
41
|
+
| 'type'
|
|
42
|
+
| keyof ValidityHandlerProps
|
|
43
|
+
> &
|
|
44
|
+
Partial<ValidityHandlerProps> & {
|
|
45
|
+
role?: BooleanControlRole
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type UseBooleanControlResult = {
|
|
49
|
+
booleanControlProps: BooleanControlRenderProps
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type BooleanControlProps = UseBooleanControlOptions & {
|
|
53
|
+
children: (props: BooleanControlRenderArgs) => ReactNode
|
|
54
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
BooleanControlProps,
|
|
3
|
+
BooleanControlRenderArgs,
|
|
4
|
+
BooleanControlRenderProps,
|
|
5
|
+
BooleanControlRole,
|
|
6
|
+
UseBooleanControlOptions,
|
|
7
|
+
UseBooleanControlResult,
|
|
8
|
+
} from './BooleanControl.types'
|
|
9
|
+
export { BooleanControl } from './BooleanControl'
|
|
10
|
+
export { useBooleanControl } from './useBooleanControl'
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BooleanControlRenderProps,
|
|
3
|
+
UseBooleanControlOptions,
|
|
4
|
+
UseBooleanControlResult,
|
|
5
|
+
} from './BooleanControl.types'
|
|
6
|
+
import type {
|
|
7
|
+
FieldContextValue,
|
|
8
|
+
FieldControlRenderProps,
|
|
9
|
+
ValidityHandlerProps,
|
|
10
|
+
} from '@maratus-component/field'
|
|
11
|
+
import { useFieldContext, useFieldControl } from '@maratus-component/field'
|
|
12
|
+
import { mergeRefs } from '@maratus-lib/props'
|
|
13
|
+
|
|
14
|
+
export function useBooleanControl(
|
|
15
|
+
options: UseBooleanControlOptions = {},
|
|
16
|
+
): UseBooleanControlResult {
|
|
17
|
+
const { role, ...fieldControlOptions } = options
|
|
18
|
+
const field = useFieldContext('BooleanControl')
|
|
19
|
+
const { fieldControlProps, validityHandlerProps } =
|
|
20
|
+
useFieldControl(fieldControlOptions)
|
|
21
|
+
const controlProps = {
|
|
22
|
+
...fieldControlProps,
|
|
23
|
+
...validityHandlerProps,
|
|
24
|
+
ref: mergeRefs(fieldControlProps.ref, validityHandlerProps.ref),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (role) {
|
|
28
|
+
return {
|
|
29
|
+
booleanControlProps: {
|
|
30
|
+
...controlProps,
|
|
31
|
+
...(field.isRequired ? { 'aria-required': true } : {}),
|
|
32
|
+
role,
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
booleanControlProps: getNativeBooleanControlProps(controlProps, field),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getNativeBooleanControlProps(
|
|
43
|
+
fieldControlProps: FieldControlRenderProps & ValidityHandlerProps,
|
|
44
|
+
field: FieldContextValue,
|
|
45
|
+
): BooleanControlRenderProps {
|
|
46
|
+
const booleanControlProps = { ...fieldControlProps }
|
|
47
|
+
|
|
48
|
+
delete booleanControlProps['aria-readonly']
|
|
49
|
+
delete booleanControlProps['aria-required']
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
...booleanControlProps,
|
|
53
|
+
...(field.isLoading ? { disabled: true } : {}),
|
|
54
|
+
name: field.name,
|
|
55
|
+
...(field.isRequired ? { required: true } : {}),
|
|
56
|
+
type: 'checkbox',
|
|
57
|
+
}
|
|
58
|
+
}
|
package/README.md
DELETED