@maratus-registry/field 0.0.0 → 0.2.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.
@@ -0,0 +1,21 @@
1
+ import type { UseFieldRootOptions, UseFieldRootResult } from './Field.types'
2
+ import clsx from 'clsx'
3
+ import './Field.css'
4
+
5
+ export function useFieldRoot(options: UseFieldRootOptions): UseFieldRootResult {
6
+ const {
7
+ 'aria-busy': ariaBusy,
8
+ className,
9
+ isLoading = false,
10
+ ...rootProps
11
+ } = options
12
+
13
+ return {
14
+ fieldRootProps: {
15
+ ...rootProps,
16
+ 'aria-busy': ariaBusy ?? (isLoading ? true : undefined),
17
+ className: clsx('maratus__Field__field', className),
18
+ 'data-loading': isLoading ? '' : undefined,
19
+ },
20
+ }
21
+ }
@@ -0,0 +1,22 @@
1
+ import type { UseLabelOptions, UseLabelResult } from './Field.types'
2
+ import clsx from 'clsx'
3
+ import { useFieldContext } from './useFieldContext'
4
+ import './Field.css'
5
+
6
+ export function useLabel(options: UseLabelOptions): UseLabelResult {
7
+ const { children, className, htmlFor, id, ...labelRootProps } = options
8
+ const field = useFieldContext('Label')
9
+
10
+ return {
11
+ labelProps: {
12
+ ...labelRootProps,
13
+ children: children ?? field.label,
14
+ className: clsx('maratus__Field__label', className),
15
+ 'data-loading': field.isLoading ? '' : undefined,
16
+ 'data-readonly': field.isReadOnly ? '' : undefined,
17
+ 'data-required': field.isRequired ? '' : undefined,
18
+ htmlFor: htmlFor ?? field.controlId,
19
+ id: id ?? field.labelId,
20
+ },
21
+ }
22
+ }
@@ -1,6 +0,0 @@
1
- export { useControl } from './useControl'
2
- export { useDescription } from './useDescription'
3
- export { useErrorMessage } from './useErrorMessage'
4
- export { useFieldContext } from './useFieldContext'
5
- export { useFieldRoot } from './useFieldRoot'
6
- export { useLabel } from './useLabel'
@@ -1,6 +0,0 @@
1
- export { useControl } from './useControl'
2
- export { useDescription } from './useDescription'
3
- export { useErrorMessage } from './useErrorMessage'
4
- export { useFieldContext } from './useFieldContext'
5
- export { useFieldRoot } from './useFieldRoot'
6
- export { useLabel } from './useLabel'
@@ -1,6 +0,0 @@
1
- export { useControl } from './useControl'
2
- export { useDescription } from './useDescription'
3
- export { useErrorMessage } from './useErrorMessage'
4
- export { useFieldContext } from './useFieldContext'
5
- export { useFieldRoot } from './useFieldRoot'
6
- export { useLabel } from './useLabel'