@maratus-registry/text-control 0.0.0-pr.15.field-widgets.8daa97e-20261122224005
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/TextControl.tsx +9 -0
- package/css-files/TextControl.types.ts +51 -0
- package/css-files/index.ts +10 -0
- package/css-files/useTextControl.ts +57 -0
- package/css-modules/TextControl.tsx +9 -0
- package/css-modules/TextControl.types.ts +51 -0
- package/css-modules/index.ts +10 -0
- package/css-modules/useTextControl.ts +57 -0
- package/meta.json +5 -0
- package/package.json +21 -0
- package/tailwind-css/TextControl.tsx +9 -0
- package/tailwind-css/TextControl.types.ts +51 -0
- package/tailwind-css/index.ts +10 -0
- package/tailwind-css/useTextControl.ts +57 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TextControlProps } from './TextControl.types'
|
|
2
|
+
import { useTextControl } from './useTextControl'
|
|
3
|
+
|
|
4
|
+
export function TextControl(props: TextControlProps) {
|
|
5
|
+
const { children, ...hookProps } = props
|
|
6
|
+
const control = useTextControl(hookProps)
|
|
7
|
+
|
|
8
|
+
return children(control)
|
|
9
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FieldControlRenderProps,
|
|
3
|
+
ValidityHandlerProps,
|
|
4
|
+
} from '@maratus-component/field'
|
|
5
|
+
import type { ReactNode } from 'react'
|
|
6
|
+
|
|
7
|
+
export type TextControlRole = 'combobox' | 'searchbox' | 'textbox'
|
|
8
|
+
|
|
9
|
+
export type TextControlRenderProps = FieldControlRenderProps &
|
|
10
|
+
ValidityHandlerProps & {
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
name?: string
|
|
13
|
+
readOnly?: boolean
|
|
14
|
+
required?: boolean
|
|
15
|
+
role?: TextControlRole
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type TextControlRenderArgs = {
|
|
19
|
+
textControlProps: TextControlRenderProps
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type UseTextControlOptions = Omit<
|
|
23
|
+
TextControlRenderProps,
|
|
24
|
+
| 'aria-describedby'
|
|
25
|
+
| 'aria-busy'
|
|
26
|
+
| 'aria-disabled'
|
|
27
|
+
| 'aria-errormessage'
|
|
28
|
+
| 'aria-invalid'
|
|
29
|
+
| 'aria-readonly'
|
|
30
|
+
| 'aria-required'
|
|
31
|
+
| 'children'
|
|
32
|
+
| 'data-loading'
|
|
33
|
+
| 'disabled'
|
|
34
|
+
| 'id'
|
|
35
|
+
| 'name'
|
|
36
|
+
| 'readOnly'
|
|
37
|
+
| 'required'
|
|
38
|
+
| 'role'
|
|
39
|
+
| keyof ValidityHandlerProps
|
|
40
|
+
> &
|
|
41
|
+
Partial<ValidityHandlerProps> & {
|
|
42
|
+
role?: TextControlRole
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type UseTextControlResult = {
|
|
46
|
+
textControlProps: TextControlRenderProps
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type TextControlProps = UseTextControlOptions & {
|
|
50
|
+
children: (props: TextControlRenderArgs) => ReactNode
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
TextControlProps,
|
|
3
|
+
TextControlRenderArgs,
|
|
4
|
+
TextControlRenderProps,
|
|
5
|
+
TextControlRole,
|
|
6
|
+
UseTextControlOptions,
|
|
7
|
+
UseTextControlResult,
|
|
8
|
+
} from './TextControl.types'
|
|
9
|
+
export { TextControl } from './TextControl'
|
|
10
|
+
export { useTextControl } from './useTextControl'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TextControlRenderProps,
|
|
3
|
+
UseTextControlOptions,
|
|
4
|
+
UseTextControlResult,
|
|
5
|
+
} from './TextControl.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 useTextControl(
|
|
15
|
+
options: UseTextControlOptions = {},
|
|
16
|
+
): UseTextControlResult {
|
|
17
|
+
const { role, ...fieldControlOptions } = options
|
|
18
|
+
const field = useFieldContext('TextControl')
|
|
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
|
+
textControlProps: {
|
|
30
|
+
...controlProps,
|
|
31
|
+
role,
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
textControlProps: getNativeTextControlProps(controlProps, field),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getNativeTextControlProps(
|
|
42
|
+
fieldControlProps: FieldControlRenderProps & ValidityHandlerProps,
|
|
43
|
+
field: FieldContextValue,
|
|
44
|
+
): TextControlRenderProps {
|
|
45
|
+
const textControlProps = { ...fieldControlProps }
|
|
46
|
+
|
|
47
|
+
delete textControlProps['aria-readonly']
|
|
48
|
+
delete textControlProps['aria-required']
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
...textControlProps,
|
|
52
|
+
...(field.isLoading ? { disabled: true } : {}),
|
|
53
|
+
name: field.name,
|
|
54
|
+
...(field.isReadOnly ? { readOnly: true } : {}),
|
|
55
|
+
...(field.isRequired ? { required: true } : {}),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TextControlProps } from './TextControl.types'
|
|
2
|
+
import { useTextControl } from './useTextControl'
|
|
3
|
+
|
|
4
|
+
export function TextControl(props: TextControlProps) {
|
|
5
|
+
const { children, ...hookProps } = props
|
|
6
|
+
const control = useTextControl(hookProps)
|
|
7
|
+
|
|
8
|
+
return children(control)
|
|
9
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FieldControlRenderProps,
|
|
3
|
+
ValidityHandlerProps,
|
|
4
|
+
} from '@maratus-component/field'
|
|
5
|
+
import type { ReactNode } from 'react'
|
|
6
|
+
|
|
7
|
+
export type TextControlRole = 'combobox' | 'searchbox' | 'textbox'
|
|
8
|
+
|
|
9
|
+
export type TextControlRenderProps = FieldControlRenderProps &
|
|
10
|
+
ValidityHandlerProps & {
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
name?: string
|
|
13
|
+
readOnly?: boolean
|
|
14
|
+
required?: boolean
|
|
15
|
+
role?: TextControlRole
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type TextControlRenderArgs = {
|
|
19
|
+
textControlProps: TextControlRenderProps
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type UseTextControlOptions = Omit<
|
|
23
|
+
TextControlRenderProps,
|
|
24
|
+
| 'aria-describedby'
|
|
25
|
+
| 'aria-busy'
|
|
26
|
+
| 'aria-disabled'
|
|
27
|
+
| 'aria-errormessage'
|
|
28
|
+
| 'aria-invalid'
|
|
29
|
+
| 'aria-readonly'
|
|
30
|
+
| 'aria-required'
|
|
31
|
+
| 'children'
|
|
32
|
+
| 'data-loading'
|
|
33
|
+
| 'disabled'
|
|
34
|
+
| 'id'
|
|
35
|
+
| 'name'
|
|
36
|
+
| 'readOnly'
|
|
37
|
+
| 'required'
|
|
38
|
+
| 'role'
|
|
39
|
+
| keyof ValidityHandlerProps
|
|
40
|
+
> &
|
|
41
|
+
Partial<ValidityHandlerProps> & {
|
|
42
|
+
role?: TextControlRole
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type UseTextControlResult = {
|
|
46
|
+
textControlProps: TextControlRenderProps
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type TextControlProps = UseTextControlOptions & {
|
|
50
|
+
children: (props: TextControlRenderArgs) => ReactNode
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
TextControlProps,
|
|
3
|
+
TextControlRenderArgs,
|
|
4
|
+
TextControlRenderProps,
|
|
5
|
+
TextControlRole,
|
|
6
|
+
UseTextControlOptions,
|
|
7
|
+
UseTextControlResult,
|
|
8
|
+
} from './TextControl.types'
|
|
9
|
+
export { TextControl } from './TextControl'
|
|
10
|
+
export { useTextControl } from './useTextControl'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TextControlRenderProps,
|
|
3
|
+
UseTextControlOptions,
|
|
4
|
+
UseTextControlResult,
|
|
5
|
+
} from './TextControl.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 useTextControl(
|
|
15
|
+
options: UseTextControlOptions = {},
|
|
16
|
+
): UseTextControlResult {
|
|
17
|
+
const { role, ...fieldControlOptions } = options
|
|
18
|
+
const field = useFieldContext('TextControl')
|
|
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
|
+
textControlProps: {
|
|
30
|
+
...controlProps,
|
|
31
|
+
role,
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
textControlProps: getNativeTextControlProps(controlProps, field),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getNativeTextControlProps(
|
|
42
|
+
fieldControlProps: FieldControlRenderProps & ValidityHandlerProps,
|
|
43
|
+
field: FieldContextValue,
|
|
44
|
+
): TextControlRenderProps {
|
|
45
|
+
const textControlProps = { ...fieldControlProps }
|
|
46
|
+
|
|
47
|
+
delete textControlProps['aria-readonly']
|
|
48
|
+
delete textControlProps['aria-required']
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
...textControlProps,
|
|
52
|
+
...(field.isLoading ? { disabled: true } : {}),
|
|
53
|
+
name: field.name,
|
|
54
|
+
...(field.isReadOnly ? { readOnly: true } : {}),
|
|
55
|
+
...(field.isRequired ? { required: true } : {}),
|
|
56
|
+
}
|
|
57
|
+
}
|
package/meta.json
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@maratus-registry/text-control",
|
|
3
|
+
"version": "0.0.0-pr.15.field-widgets.8daa97e-20261122224005",
|
|
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.0.0-pr.15.field-widgets.8daa97e-20261122224005",
|
|
14
|
+
"@maratus-registry/field": "0.0.0-pr.15.field-widgets.8daa97e-20261122224005"
|
|
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 { TextControlProps } from './TextControl.types'
|
|
2
|
+
import { useTextControl } from './useTextControl'
|
|
3
|
+
|
|
4
|
+
export function TextControl(props: TextControlProps) {
|
|
5
|
+
const { children, ...hookProps } = props
|
|
6
|
+
const control = useTextControl(hookProps)
|
|
7
|
+
|
|
8
|
+
return children(control)
|
|
9
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FieldControlRenderProps,
|
|
3
|
+
ValidityHandlerProps,
|
|
4
|
+
} from '@maratus-component/field'
|
|
5
|
+
import type { ReactNode } from 'react'
|
|
6
|
+
|
|
7
|
+
export type TextControlRole = 'combobox' | 'searchbox' | 'textbox'
|
|
8
|
+
|
|
9
|
+
export type TextControlRenderProps = FieldControlRenderProps &
|
|
10
|
+
ValidityHandlerProps & {
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
name?: string
|
|
13
|
+
readOnly?: boolean
|
|
14
|
+
required?: boolean
|
|
15
|
+
role?: TextControlRole
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type TextControlRenderArgs = {
|
|
19
|
+
textControlProps: TextControlRenderProps
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type UseTextControlOptions = Omit<
|
|
23
|
+
TextControlRenderProps,
|
|
24
|
+
| 'aria-describedby'
|
|
25
|
+
| 'aria-busy'
|
|
26
|
+
| 'aria-disabled'
|
|
27
|
+
| 'aria-errormessage'
|
|
28
|
+
| 'aria-invalid'
|
|
29
|
+
| 'aria-readonly'
|
|
30
|
+
| 'aria-required'
|
|
31
|
+
| 'children'
|
|
32
|
+
| 'data-loading'
|
|
33
|
+
| 'disabled'
|
|
34
|
+
| 'id'
|
|
35
|
+
| 'name'
|
|
36
|
+
| 'readOnly'
|
|
37
|
+
| 'required'
|
|
38
|
+
| 'role'
|
|
39
|
+
| keyof ValidityHandlerProps
|
|
40
|
+
> &
|
|
41
|
+
Partial<ValidityHandlerProps> & {
|
|
42
|
+
role?: TextControlRole
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type UseTextControlResult = {
|
|
46
|
+
textControlProps: TextControlRenderProps
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type TextControlProps = UseTextControlOptions & {
|
|
50
|
+
children: (props: TextControlRenderArgs) => ReactNode
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
TextControlProps,
|
|
3
|
+
TextControlRenderArgs,
|
|
4
|
+
TextControlRenderProps,
|
|
5
|
+
TextControlRole,
|
|
6
|
+
UseTextControlOptions,
|
|
7
|
+
UseTextControlResult,
|
|
8
|
+
} from './TextControl.types'
|
|
9
|
+
export { TextControl } from './TextControl'
|
|
10
|
+
export { useTextControl } from './useTextControl'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TextControlRenderProps,
|
|
3
|
+
UseTextControlOptions,
|
|
4
|
+
UseTextControlResult,
|
|
5
|
+
} from './TextControl.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 useTextControl(
|
|
15
|
+
options: UseTextControlOptions = {},
|
|
16
|
+
): UseTextControlResult {
|
|
17
|
+
const { role, ...fieldControlOptions } = options
|
|
18
|
+
const field = useFieldContext('TextControl')
|
|
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
|
+
textControlProps: {
|
|
30
|
+
...controlProps,
|
|
31
|
+
role,
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
textControlProps: getNativeTextControlProps(controlProps, field),
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function getNativeTextControlProps(
|
|
42
|
+
fieldControlProps: FieldControlRenderProps & ValidityHandlerProps,
|
|
43
|
+
field: FieldContextValue,
|
|
44
|
+
): TextControlRenderProps {
|
|
45
|
+
const textControlProps = { ...fieldControlProps }
|
|
46
|
+
|
|
47
|
+
delete textControlProps['aria-readonly']
|
|
48
|
+
delete textControlProps['aria-required']
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
...textControlProps,
|
|
52
|
+
...(field.isLoading ? { disabled: true } : {}),
|
|
53
|
+
name: field.name,
|
|
54
|
+
...(field.isReadOnly ? { readOnly: true } : {}),
|
|
55
|
+
...(field.isRequired ? { required: true } : {}),
|
|
56
|
+
}
|
|
57
|
+
}
|