@plexui/vue 0.1.9 → 0.1.10
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/dist/es/components/Field/Field.js +8 -3
- package/dist/es/components/Field/Field.js.map +1 -1
- package/dist/es/components/FieldGroup/FieldGroup.js +54 -0
- package/dist/es/components/FieldGroup/FieldGroup.js.map +1 -0
- package/dist/es/components/FieldGroup/index.js +2 -0
- package/dist/es/components/FieldGroup/index.js.map +1 -0
- package/dist/types/components/Field/Field.d.ts +13 -9
- package/dist/types/components/FieldGroup/FieldGroup.d.ts +40 -0
- package/dist/types/components/FieldGroup/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -112,8 +112,10 @@ const FieldComponent = defineComponent({
|
|
|
112
112
|
size: String,
|
|
113
113
|
/** Shows a required asterisk after the label. Visual only: no `required` attribute. @default false */
|
|
114
114
|
required: { type: Boolean, default: false },
|
|
115
|
-
/** Layout direction of label and control. @default "vertical" */
|
|
116
|
-
orientation:
|
|
115
|
+
/** Layout direction of label and control. @default "horizontal" on a `row`, else "vertical" */
|
|
116
|
+
orientation: String,
|
|
117
|
+
/** One line of a FieldGroup: label at the start, control at the end. @default false */
|
|
118
|
+
row: { type: Boolean, default: false },
|
|
117
119
|
/** Overrides the generated id set on the control and the label's `for`. A child's own `id` wins over both. */
|
|
118
120
|
id: String,
|
|
119
121
|
/** Optically aligns the control's text with surrounding content; passed to the control. */
|
|
@@ -123,7 +125,8 @@ const FieldComponent = defineComponent({
|
|
|
123
125
|
setup(props, { attrs, slots }) {
|
|
124
126
|
const generatedId = useId();
|
|
125
127
|
return () => {
|
|
126
|
-
const { required,
|
|
128
|
+
const { required, row, opticallyAlign } = props;
|
|
129
|
+
const orientation = props.orientation ?? (row ? "horizontal" : "vertical");
|
|
127
130
|
const fieldId = props.id || `field-${generatedId}`;
|
|
128
131
|
const labelId = `${fieldId}-label`;
|
|
129
132
|
const description = slots.description ? slots.description() : props.description;
|
|
@@ -163,10 +166,12 @@ const FieldComponent = defineComponent({
|
|
|
163
166
|
required ? h("span", { "class": s.RequiredIndicator, "aria-hidden": "true" }, "*") : null,
|
|
164
167
|
]);
|
|
165
168
|
return h("div", {
|
|
169
|
+
...(row && attrs),
|
|
166
170
|
"class": clsx(s.Field, attrs.class),
|
|
167
171
|
"data-size": size,
|
|
168
172
|
"data-orientation": orientation,
|
|
169
173
|
"data-optically-align": opticallyAlign,
|
|
174
|
+
"data-row": row ? "" : undefined,
|
|
170
175
|
}, [
|
|
171
176
|
h("div", { class: s.LabelGroup }, [
|
|
172
177
|
hasLabelAction
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.js","sourceRoot":"","sources":["../../../../src/components/Field/Field.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAmB,MAAM,MAAM,CAAA;AAC5C,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,eAAe,EACf,CAAC,EACD,OAAO,EACP,KAAK,GAMN,MAAM,KAAK,CAAA;AAEZ,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,CAAC,MAAM,kDAAkD,CAAA;AAsChE,MAAM,aAAa,GAAyB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;AAE/G,mFAAmF;AACnF,MAAM,QAAQ,GAAG,CAAC,MAAuB,EAAE,EAAE;IAC3C,MAAM,KAAK,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;IAC7B,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,EAAE;QAC9B,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,QAAQ;YACvB,KAAK,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F,mFAAmF;AACnF,MAAM,CAAC,MAAM,KAAK,GAAG,cAA4E,CAAA","sourcesContent":["import clsx, { type ClassValue } from \"clsx\"\nimport {\n Comment,\n Fragment,\n Static,\n Text,\n camelize,\n cloneVNode,\n defineComponent,\n h,\n isVNode,\n useId,\n type PropType,\n type SlotsType,\n type VNode,\n type VNodeArrayChildren,\n type VNodeChild,\n} from \"vue\"\nimport type { ControlSize } from \"@plexui/styles/types\"\nimport { FieldError } from \"../FieldError/index.js\"\nimport { hasContent } from \"../../lib/slotContent.js\"\nimport s from \"@plexui/styles/components/Field/Field.module.css\"\n\n// Vue port of packages/ui/src/components/Field/Field.tsx.\n//\n// - `label`, `description` and `errorMessage` take a string prop or a slot of\n// the same name (the slot wins), like React's ReactNode props.\n// - Children: React accepts an element, which Field clones with the field\n// props, or a render prop `(fieldProps) => ReactNode`, which it leaves alone.\n// Both are the default slot here, which receives the field props:\n// - a slot that reads them (`v-slot=\"fieldProps\"` + `v-bind=\"fieldProps\"`,\n// `v-slot=\"{ id }\"`, `(fieldProps) => h(...)`) is the render prop: its\n// content renders as it is.\n// - a slot that does not read them and holds exactly one element or\n// component gets it cloned like React's `cloneElement`: `opticallyAlign`\n// replaces the child's own, the child's own `id` stays and the label's\n// `for` follows it, `aria-describedby` is joined after the child's own\n// ids, and an explicit `aria-invalid` on the child wins. Template\n// comments do not count as children (JSX comments); the\n// placeholder of a `v-if` that renders nothing does, like `{false}` in a\n// React children array, so `<A v-if=\"x\" /><Input />` is not cloned.\n// - anything else (text, several roots, a `v-for` list) renders as it is,\n// like a React child that is not a single element.\n// - content a wrapper forwards with `<slot />` counts as its own roots, as\n// React's `children` passed on to Field are the elements themselves.\n// - As in React only `class` reaches the root element; other attributes are\n// dropped.\n\nexport type FieldChildProps = {\n id: string\n /** The label's id. Bind it to a control that the label's `for` cannot name, such as a Select trigger. */\n \"aria-labelledby\"?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n opticallyAlign?: \"start\" | \"end\"\n}\n\ntype Props = Record<string, unknown>\n\nconst CONTROL_SIZES: ReadonlySet<unknown> = new Set([\"3xs\", \"2xs\", \"xs\", \"sm\", \"md\", \"lg\", \"xl\", \"2xl\", \"3xl\"])\n\n/** The slot props, recording whether the slot read them (the render-prop form). */\nconst trackUse = (target: FieldChildProps) => {\n const state = { used: false }\n const proxy = new Proxy(target, {\n get(object, key, receiver) {\n state.used = true\n return Reflect.get(object, key, receiver)\n },\n has(object, key) {\n state.used = true\n return Reflect.has(object, key)\n },\n ownKeys(object) {\n state.used = true\n return Reflect.ownKeys(object)\n },\n getOwnPropertyDescriptor(object, key) {\n state.used = true\n return Reflect.getOwnPropertyDescriptor(object, key)\n },\n })\n return { proxy, state }\n}\n\n/** Like React's `isValidElement` for a slot root: an element or a component. */\nconst isElementVNode = (node: VNode) => {\n const { type } = node\n if (type === Fragment || type === Text || type === Comment || type === Static) return false\n if (typeof type === \"object\" && type !== null && (\"__isTeleport\" in type || \"__isSuspense\" in type)) return false\n return true\n}\n\n/**\n * Template comments (`<!-- note -->`) are no children, like JSX comments.\n * The empty placeholder of a `v-if` that renders nothing (or of a `false`\n * child) still counts, like `{false}` in a React children array.\n */\nconst isTemplateComment = (node: VNodeArrayChildren[number]) =>\n isVNode(node) && node.type === Comment && !!node.children && node.children !== \"v-if\"\n\n/**\n * Unwraps content forwarded through a wrapper's `<slot />`: the fragment\n * `renderSlot` creates, keyed `_<slot name>`.\n */\nconst unwrapForwardedSlots = (nodes: VNodeArrayChildren): VNodeArrayChildren =>\n nodes.flatMap((node) =>\n isVNode(node) &&\n node.type === Fragment &&\n typeof node.key === \"string\" &&\n node.key.startsWith(\"_\") &&\n Array.isArray(node.children)\n ? unwrapForwardedSlots(node.children)\n : [node],\n )\n\n/** The one element a non-render-prop slot holds, if it holds exactly one. */\nconst singleElement = (nodes: VNodeArrayChildren): VNode | undefined => {\n const roots = unwrapForwardedSlots(nodes).filter((node) => !isTemplateComment(node))\n if (roots.length !== 1) return undefined\n const [root] = roots\n return isVNode(root) && isElementVNode(root) ? root : undefined\n}\n\n/** A child prop under its attribute name or its camelCase prop name. */\nconst childProp = (props: Props, name: string) => props[name] ?? props[camelize(name)]\n\n/**\n * `cloneElement(child, fieldProps)` with React Field's merging rules. A child\n * without its own name (`aria-label`, `aria-labelledby`, `label`, a `#label`\n * slot) is also labelled by the field's label, which names triggers `for`\n * cannot reach.\n */\nconst cloneWithFieldProps = (child: VNode, fieldChildProps: FieldChildProps, labelId: string): VNode => {\n const own: Props = { ...(child.props ?? {}) }\n const childDescribedBy = childProp(own, \"aria-describedby\") as string | undefined\n const childInvalid = childProp(own, \"aria-invalid\")\n const childSlots = child.children\n const childNamed =\n childProp(own, \"aria-label\") != null ||\n childProp(own, \"aria-labelledby\") != null ||\n own.label != null ||\n (childSlots != null && typeof childSlots === \"object\" && !Array.isArray(childSlots) && \"label\" in childSlots)\n\n const overrides: Props = {\n ...fieldChildProps,\n // Merge with the child's own associations instead of overwriting them\n \"aria-describedby\": [childDescribedBy, fieldChildProps[\"aria-describedby\"]].filter(Boolean).join(\" \") || undefined,\n \"aria-invalid\": childInvalid ?? fieldChildProps[\"aria-invalid\"],\n ...(!childNamed && { \"aria-labelledby\": labelId }),\n }\n\n // One spelling per prop, so the field's value is the one that applies\n for (const key of Object.keys(overrides)) {\n for (const spelling of [key, camelize(key), key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)]) {\n delete own[spelling]\n }\n }\n\n return cloneVNode({ ...child, props: own } as VNode, overrides)\n}\n\nconst FieldComponent = defineComponent({\n name: \"Field\",\n inheritAttrs: false,\n props: {\n /** Label text for the field (or the `label` slot) */\n label: String,\n /** Helper text below the label, linked via `aria-describedby` (or the `description` slot) */\n description: String,\n /**\n * Error message below the control (or the `errorMessage` slot). When set,\n * the control gets `aria-invalid=\"true\"`. Rendered with FieldError.\n */\n errorMessage: String,\n /** Content at the end of the label row, such as a link that acts on the field (or the `labelAction` slot) */\n labelAction: String,\n /** Font size of the label, to match the control's size. @default the child control's `size`, else \"md\" */\n size: String as PropType<ControlSize>,\n /** Shows a required asterisk after the label. Visual only: no `required` attribute. @default false */\n required: { type: Boolean, default: false },\n /** Layout direction of label and control. @default \"vertical\" */\n orientation: { type: String as PropType<\"vertical\" | \"horizontal\">, default: \"vertical\" },\n /** Overrides the generated id set on the control and the label's `for`. A child's own `id` wins over both. */\n id: String,\n /** Optically aligns the control's text with surrounding content; passed to the control. */\n opticallyAlign: String as PropType<\"start\" | \"end\">,\n },\n slots: Object as SlotsType<{\n /** The control. Read the props to render them yourself (React's render prop). */\n default?: (fieldProps: FieldChildProps) => VNodeChild\n label?: () => VNodeChild\n labelAction?: () => VNodeChild\n description?: () => VNodeChild\n errorMessage?: () => VNodeChild\n }>,\n setup(props, { attrs, slots }) {\n const generatedId = useId()\n\n return () => {\n const { required, orientation, opticallyAlign } = props\n const fieldId = props.id || `field-${generatedId}`\n const labelId = `${fieldId}-label`\n\n const description = slots.description ? slots.description() : props.description\n const hasDescription = slots.description ? hasContent(description as VNodeArrayChildren) : !!description\n const errorMessage = slots.errorMessage ? slots.errorMessage() : props.errorMessage\n const hasError = slots.errorMessage ? hasContent(errorMessage as VNodeArrayChildren) : !!errorMessage\n\n const descriptionId = hasDescription ? `${fieldId}-description` : undefined\n const errorId = hasError ? `${fieldId}-error` : undefined\n\n // Build aria-describedby from description + error IDs\n const ariaDescribedBy = [descriptionId, errorId].filter(Boolean).join(\" \") || undefined\n const invalid = hasError\n\n // Props to inject into the child control\n const fieldChildProps: FieldChildProps = {\n \"id\": fieldId,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": invalid || undefined,\n ...(opticallyAlign && { opticallyAlign }),\n }\n\n // Resolve the children\n let resolvedChildren: VNodeArrayChildren | undefined\n let childSize: unknown\n // The control's id, which the label's `for` has to match\n let controlId = fieldId\n if (slots.default) {\n const { proxy, state } = trackUse({ ...fieldChildProps, \"aria-labelledby\": labelId })\n const nodes = slots.default(proxy) as VNodeArrayChildren\n const child = state.used ? undefined : singleElement(nodes)\n childSize = child?.props?.size\n controlId = (child?.props?.id as string | undefined) || fieldId\n resolvedChildren = child ? [cloneWithFieldProps(child, { ...fieldChildProps, id: controlId }, labelId)] : nodes\n }\n const size = props.size ?? (CONTROL_SIZES.has(childSize) ? (childSize as ControlSize) : \"md\")\n\n const labelAction = slots.labelAction ? slots.labelAction() : props.labelAction\n const hasLabelAction = slots.labelAction ? hasContent(labelAction as VNodeArrayChildren) : !!labelAction\n const labelElement = h(\"label\", { class: s.Label, id: labelId, for: controlId }, [\n slots.label ? slots.label() : props.label,\n required ? h(\"span\", { \"class\": s.RequiredIndicator, \"aria-hidden\": \"true\" }, \"*\") : null,\n ])\n\n return h(\n \"div\",\n {\n \"class\": clsx(s.Field, attrs.class as ClassValue),\n \"data-size\": size,\n \"data-orientation\": orientation,\n \"data-optically-align\": opticallyAlign,\n },\n [\n h(\"div\", { class: s.LabelGroup }, [\n hasLabelAction\n ? h(\"div\", { class: s.LabelRow }, [labelElement, h(\"div\", { class: s.LabelAction }, [labelAction as VNodeChild])])\n : labelElement,\n hasDescription ? h(\"div\", { class: s.Description, id: descriptionId }, [description as VNodeChild]) : null,\n ]),\n h(\"div\", { class: s.Content }, [\n h(\"div\", { class: s.Control }, resolvedChildren),\n hasError ? h(FieldError, { id: errorId }, () => [errorMessage as VNodeChild]) : null,\n ]),\n ],\n )\n }\n },\n})\n\ntype FieldOwnProps = InstanceType<typeof FieldComponent>[\"$props\"]\n\n/** Field props; `class` reaches the root element. */\nexport type FieldProps = FieldOwnProps & { class?: ClassValue }\n\n/** Form field wrapper with label, description, error and accessibility linking. */\nexport const Field = FieldComponent as typeof FieldComponent & { new (): { $props: FieldProps } }\n"]}
|
|
1
|
+
{"version":3,"file":"Field.js","sourceRoot":"","sources":["../../../../src/components/Field/Field.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAmB,MAAM,MAAM,CAAA;AAC5C,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MA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EACD;gBACE,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,UAAU,EAAE,EAAE;oBAChC,cAAc;wBACZ,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,YAAY,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAyB,CAAC,CAAC,CAAC,CAAC;wBAClH,CAAC,CAAC,YAAY;oBAChB,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,EAAE,aAAa,EAAE,EAAE,CAAC,WAAyB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;iBAC3G,CAAC;gBACF,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE;oBAC7B,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,gBAAgB,CAAC;oBAChD,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,YAA0B,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI;iBACrF,CAAC;aACH,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAOF,mFAAmF;AACnF,MAAM,CAAC,MAAM,KAAK,GAAG,cAA4E,CAAA","sourcesContent":["import clsx, { type ClassValue } from \"clsx\"\nimport {\n Comment,\n Fragment,\n Static,\n Text,\n camelize,\n cloneVNode,\n defineComponent,\n h,\n isVNode,\n useId,\n type PropType,\n type SlotsType,\n type VNode,\n type VNodeArrayChildren,\n type VNodeChild,\n} from \"vue\"\nimport type { ControlSize } from \"@plexui/styles/types\"\nimport { FieldError } from \"../FieldError/index.js\"\nimport { hasContent } from \"../../lib/slotContent.js\"\nimport s from \"@plexui/styles/components/Field/Field.module.css\"\n\n// Vue port of packages/ui/src/components/Field/Field.tsx.\n//\n// - `label`, `description` and `errorMessage` take a string prop or a slot of\n// the same name (the slot wins), like React's ReactNode props.\n// - Children: React accepts an element, which Field clones with the field\n// props, or a render prop `(fieldProps) => ReactNode`, which it leaves alone.\n// Both are the default slot here, which receives the field props:\n// - a slot that reads them (`v-slot=\"fieldProps\"` + `v-bind=\"fieldProps\"`,\n// `v-slot=\"{ id }\"`, `(fieldProps) => h(...)`) is the render prop: its\n// content renders as it is.\n// - a slot that does not read them and holds exactly one element or\n// component gets it cloned like React's `cloneElement`: `opticallyAlign`\n// replaces the child's own, the child's own `id` stays and the label's\n// `for` follows it, `aria-describedby` is joined after the child's own\n// ids, and an explicit `aria-invalid` on the child wins. Template\n// comments do not count as children (JSX comments); the\n// placeholder of a `v-if` that renders nothing does, like `{false}` in a\n// React children array, so `<A v-if=\"x\" /><Input />` is not cloned.\n// - anything else (text, several roots, a `v-for` list) renders as it is,\n// like a React child that is not a single element.\n// - content a wrapper forwards with `<slot />` counts as its own roots, as\n// React's `children` passed on to Field are the elements themselves.\n// - As in React only `class` reaches the root element; other attributes are\n// dropped. On a `row` they all reach it, as React's rest props do.\n\nexport type FieldChildProps = {\n id: string\n /** The label's id. Bind it to a control that the label's `for` cannot name, such as a Select trigger. */\n \"aria-labelledby\"?: string\n \"aria-describedby\"?: string\n \"aria-invalid\"?: boolean\n opticallyAlign?: \"start\" | \"end\"\n}\n\ntype Props = Record<string, unknown>\n\nconst CONTROL_SIZES: ReadonlySet<unknown> = new Set([\"3xs\", \"2xs\", \"xs\", \"sm\", \"md\", \"lg\", \"xl\", \"2xl\", \"3xl\"])\n\n/** The slot props, recording whether the slot read them (the render-prop form). */\nconst trackUse = (target: FieldChildProps) => {\n const state = { used: false }\n const proxy = new Proxy(target, {\n get(object, key, receiver) {\n state.used = true\n return Reflect.get(object, key, receiver)\n },\n has(object, key) {\n state.used = true\n return Reflect.has(object, key)\n },\n ownKeys(object) {\n state.used = true\n return Reflect.ownKeys(object)\n },\n getOwnPropertyDescriptor(object, key) {\n state.used = true\n return Reflect.getOwnPropertyDescriptor(object, key)\n },\n })\n return { proxy, state }\n}\n\n/** Like React's `isValidElement` for a slot root: an element or a component. */\nconst isElementVNode = (node: VNode) => {\n const { type } = node\n if (type === Fragment || type === Text || type === Comment || type === Static) return false\n if (typeof type === \"object\" && type !== null && (\"__isTeleport\" in type || \"__isSuspense\" in type)) return false\n return true\n}\n\n/**\n * Template comments (`<!-- note -->`) are no children, like JSX comments.\n * The empty placeholder of a `v-if` that renders nothing (or of a `false`\n * child) still counts, like `{false}` in a React children array.\n */\nconst isTemplateComment = (node: VNodeArrayChildren[number]) =>\n isVNode(node) && node.type === Comment && !!node.children && node.children !== \"v-if\"\n\n/**\n * Unwraps content forwarded through a wrapper's `<slot />`: the fragment\n * `renderSlot` creates, keyed `_<slot name>`.\n */\nconst unwrapForwardedSlots = (nodes: VNodeArrayChildren): VNodeArrayChildren =>\n nodes.flatMap((node) =>\n isVNode(node) &&\n node.type === Fragment &&\n typeof node.key === \"string\" &&\n node.key.startsWith(\"_\") &&\n Array.isArray(node.children)\n ? unwrapForwardedSlots(node.children)\n : [node],\n )\n\n/** The one element a non-render-prop slot holds, if it holds exactly one. */\nconst singleElement = (nodes: VNodeArrayChildren): VNode | undefined => {\n const roots = unwrapForwardedSlots(nodes).filter((node) => !isTemplateComment(node))\n if (roots.length !== 1) return undefined\n const [root] = roots\n return isVNode(root) && isElementVNode(root) ? root : undefined\n}\n\n/** A child prop under its attribute name or its camelCase prop name. */\nconst childProp = (props: Props, name: string) => props[name] ?? props[camelize(name)]\n\n/**\n * `cloneElement(child, fieldProps)` with React Field's merging rules. A child\n * without its own name (`aria-label`, `aria-labelledby`, `label`, a `#label`\n * slot) is also labelled by the field's label, which names triggers `for`\n * cannot reach.\n */\nconst cloneWithFieldProps = (child: VNode, fieldChildProps: FieldChildProps, labelId: string): VNode => {\n const own: Props = { ...(child.props ?? {}) }\n const childDescribedBy = childProp(own, \"aria-describedby\") as string | undefined\n const childInvalid = childProp(own, \"aria-invalid\")\n const childSlots = child.children\n const childNamed =\n childProp(own, \"aria-label\") != null ||\n childProp(own, \"aria-labelledby\") != null ||\n own.label != null ||\n (childSlots != null && typeof childSlots === \"object\" && !Array.isArray(childSlots) && \"label\" in childSlots)\n\n const overrides: Props = {\n ...fieldChildProps,\n // Merge with the child's own associations instead of overwriting them\n \"aria-describedby\": [childDescribedBy, fieldChildProps[\"aria-describedby\"]].filter(Boolean).join(\" \") || undefined,\n \"aria-invalid\": childInvalid ?? fieldChildProps[\"aria-invalid\"],\n ...(!childNamed && { \"aria-labelledby\": labelId }),\n }\n\n // One spelling per prop, so the field's value is the one that applies\n for (const key of Object.keys(overrides)) {\n for (const spelling of [key, camelize(key), key.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)]) {\n delete own[spelling]\n }\n }\n\n return cloneVNode({ ...child, props: own } as VNode, overrides)\n}\n\nconst FieldComponent = defineComponent({\n name: \"Field\",\n inheritAttrs: false,\n props: {\n /** Label text for the field (or the `label` slot) */\n label: String,\n /** Helper text below the label, linked via `aria-describedby` (or the `description` slot) */\n description: String,\n /**\n * Error message below the control (or the `errorMessage` slot). When set,\n * the control gets `aria-invalid=\"true\"`. Rendered with FieldError.\n */\n errorMessage: String,\n /** Content at the end of the label row, such as a link that acts on the field (or the `labelAction` slot) */\n labelAction: String,\n /** Font size of the label, to match the control's size. @default the child control's `size`, else \"md\" */\n size: String as PropType<ControlSize>,\n /** Shows a required asterisk after the label. Visual only: no `required` attribute. @default false */\n required: { type: Boolean, default: false },\n /** Layout direction of label and control. @default \"horizontal\" on a `row`, else \"vertical\" */\n orientation: String as PropType<\"vertical\" | \"horizontal\">,\n /** One line of a FieldGroup: label at the start, control at the end. @default false */\n row: { type: Boolean, default: false },\n /** Overrides the generated id set on the control and the label's `for`. A child's own `id` wins over both. */\n id: String,\n /** Optically aligns the control's text with surrounding content; passed to the control. */\n opticallyAlign: String as PropType<\"start\" | \"end\">,\n },\n slots: Object as SlotsType<{\n /** The control. Read the props to render them yourself (React's render prop). */\n default?: (fieldProps: FieldChildProps) => VNodeChild\n label?: () => VNodeChild\n labelAction?: () => VNodeChild\n description?: () => VNodeChild\n errorMessage?: () => VNodeChild\n }>,\n setup(props, { attrs, slots }) {\n const generatedId = useId()\n\n return () => {\n const { required, row, opticallyAlign } = props\n const orientation = props.orientation ?? (row ? \"horizontal\" : \"vertical\")\n const fieldId = props.id || `field-${generatedId}`\n const labelId = `${fieldId}-label`\n\n const description = slots.description ? slots.description() : props.description\n const hasDescription = slots.description ? hasContent(description as VNodeArrayChildren) : !!description\n const errorMessage = slots.errorMessage ? slots.errorMessage() : props.errorMessage\n const hasError = slots.errorMessage ? hasContent(errorMessage as VNodeArrayChildren) : !!errorMessage\n\n const descriptionId = hasDescription ? `${fieldId}-description` : undefined\n const errorId = hasError ? `${fieldId}-error` : undefined\n\n // Build aria-describedby from description + error IDs\n const ariaDescribedBy = [descriptionId, errorId].filter(Boolean).join(\" \") || undefined\n const invalid = hasError\n\n // Props to inject into the child control\n const fieldChildProps: FieldChildProps = {\n \"id\": fieldId,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": invalid || undefined,\n ...(opticallyAlign && { opticallyAlign }),\n }\n\n // Resolve the children\n let resolvedChildren: VNodeArrayChildren | undefined\n let childSize: unknown\n // The control's id, which the label's `for` has to match\n let controlId = fieldId\n if (slots.default) {\n const { proxy, state } = trackUse({ ...fieldChildProps, \"aria-labelledby\": labelId })\n const nodes = slots.default(proxy) as VNodeArrayChildren\n const child = state.used ? undefined : singleElement(nodes)\n childSize = child?.props?.size\n controlId = (child?.props?.id as string | undefined) || fieldId\n resolvedChildren = child ? [cloneWithFieldProps(child, { ...fieldChildProps, id: controlId }, labelId)] : nodes\n }\n const size = props.size ?? (CONTROL_SIZES.has(childSize) ? (childSize as ControlSize) : \"md\")\n\n const labelAction = slots.labelAction ? slots.labelAction() : props.labelAction\n const hasLabelAction = slots.labelAction ? hasContent(labelAction as VNodeArrayChildren) : !!labelAction\n const labelElement = h(\"label\", { class: s.Label, id: labelId, for: controlId }, [\n slots.label ? slots.label() : props.label,\n required ? h(\"span\", { \"class\": s.RequiredIndicator, \"aria-hidden\": \"true\" }, \"*\") : null,\n ])\n\n return h(\n \"div\",\n {\n ...(row && attrs),\n \"class\": clsx(s.Field, attrs.class as ClassValue),\n \"data-size\": size,\n \"data-orientation\": orientation,\n \"data-optically-align\": opticallyAlign,\n \"data-row\": row ? \"\" : undefined,\n },\n [\n h(\"div\", { class: s.LabelGroup }, [\n hasLabelAction\n ? h(\"div\", { class: s.LabelRow }, [labelElement, h(\"div\", { class: s.LabelAction }, [labelAction as VNodeChild])])\n : labelElement,\n hasDescription ? h(\"div\", { class: s.Description, id: descriptionId }, [description as VNodeChild]) : null,\n ]),\n h(\"div\", { class: s.Content }, [\n h(\"div\", { class: s.Control }, resolvedChildren),\n hasError ? h(FieldError, { id: errorId }, () => [errorMessage as VNodeChild]) : null,\n ]),\n ],\n )\n }\n },\n})\n\ntype FieldOwnProps = InstanceType<typeof FieldComponent>[\"$props\"]\n\n/** Field props; `class` reaches the root element. */\nexport type FieldProps = FieldOwnProps & { class?: ClassValue }\n\n/** Form field wrapper with label, description, error and accessibility linking. */\nexport const Field = FieldComponent as typeof FieldComponent & { new (): { $props: FieldProps } }\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import clsx, {} from "clsx";
|
|
2
|
+
import { defineComponent, h, useId } from "vue";
|
|
3
|
+
import { hasContent } from "../../lib/slotContent.js";
|
|
4
|
+
import s from "@plexui/styles/components/FieldGroup/FieldGroup.module.css";
|
|
5
|
+
// Vue port of packages/ui/src/components/FieldGroup/FieldGroup.tsx.
|
|
6
|
+
//
|
|
7
|
+
// - `title` and `description` take a string prop or a slot of the same name,
|
|
8
|
+
// like React's ReactNode props. `action` and `footer` are slots here.
|
|
9
|
+
// - Attributes reach the root `section`, as React's rest props do.
|
|
10
|
+
const FieldGroupComponent = defineComponent({
|
|
11
|
+
name: "FieldGroup",
|
|
12
|
+
inheritAttrs: false,
|
|
13
|
+
props: {
|
|
14
|
+
/** Heading over the block (or the `title` slot); it names the group */
|
|
15
|
+
title: String,
|
|
16
|
+
/** Line under the title (or the `description` slot) */
|
|
17
|
+
description: String,
|
|
18
|
+
/** Class for the block that holds the rows */
|
|
19
|
+
bodyClass: [String, Array, Object],
|
|
20
|
+
},
|
|
21
|
+
slots: Object,
|
|
22
|
+
setup(props, { attrs, slots }) {
|
|
23
|
+
const titleId = `field-group-${useId()}`;
|
|
24
|
+
return () => {
|
|
25
|
+
const title = slots.title ? slots.title() : props.title;
|
|
26
|
+
const hasTitle = slots.title ? hasContent(title) : !!title;
|
|
27
|
+
const description = slots.description ? slots.description() : props.description;
|
|
28
|
+
const hasDescription = slots.description ? hasContent(description) : !!description;
|
|
29
|
+
const action = slots.action?.();
|
|
30
|
+
const hasAction = !!action && hasContent(action);
|
|
31
|
+
return h("section", {
|
|
32
|
+
"role": "group",
|
|
33
|
+
"aria-labelledby": hasTitle ? titleId : undefined,
|
|
34
|
+
...attrs,
|
|
35
|
+
"class": clsx(s.FieldGroup, attrs.class),
|
|
36
|
+
}, [
|
|
37
|
+
hasTitle || hasDescription || hasAction
|
|
38
|
+
? h("div", { class: s.Header }, [
|
|
39
|
+
h("div", { class: s.HeaderText }, [
|
|
40
|
+
hasTitle ? h("h2", { class: s.Title, id: titleId }, [title]) : null,
|
|
41
|
+
hasDescription ? h("p", { class: s.Description }, [description]) : null,
|
|
42
|
+
]),
|
|
43
|
+
hasAction ? action : null,
|
|
44
|
+
])
|
|
45
|
+
: null,
|
|
46
|
+
h("div", { class: clsx(s.Body, props.bodyClass) }, [slots.default?.()]),
|
|
47
|
+
slots.footer?.(),
|
|
48
|
+
]);
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
/** A titled block of rows: `Field row` lines with hairlines between them. */
|
|
53
|
+
export const FieldGroup = FieldGroupComponent;
|
|
54
|
+
//# sourceMappingURL=FieldGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FieldGroup.js","sourceRoot":"","sources":["../../../../src/components/FieldGroup/FieldGroup.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,EAAE,EAAmB,MAAM,MAAM,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,KAAK,EAA2E,MAAM,KAAK,CAAA;AACxH,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,CAAC,MAAM,4DAA4D,CAAA;AAE1E,oEAAoE;AACpE,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,mEAAmE;AAEnE,MAAM,mBAAmB,GAAG,eAAe,CAAC;IAC1C,IAAI,EAAE,YAAY;IAClB,YAAY,EAAE,KAAK;IACnB,KAAK,EAAE;QACL,uEAAuE;QACvE,KAAK,EAAE,MAAM;QACb,uDAAuD;QACvD,WAAW,EAAE,MAAM;QACnB,8CAA8C;QAC9C,SAAS,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAyB;KAC3D;IACD,KAAK,EAAE,MASL;IACF,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE;QAC3B,MAAM,OAAO,GAAG,eAAe,KAAK,EAAE,EAAE,CAAA;QAExC,OAAO,GAAG,EAAE;YACV,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAA;YACvD,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,KAA2B,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;YAChF,MAAM,WAAW,G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I;qBAC1B,CAAC;oBACJ,CAAC,CAAC,IAAI;gBACR,CAAC,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;gBACvE,KAAK,CAAC,MAAM,EAAE,EAAE;aACjB,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA;AAOF,6EAA6E;AAC7E,MAAM,CAAC,MAAM,UAAU,GAAG,mBAA2F,CAAA","sourcesContent":["import clsx, { type ClassValue } from \"clsx\"\nimport { defineComponent, h, useId, type PropType, type SlotsType, type VNodeArrayChildren, type VNodeChild } from \"vue\"\nimport { hasContent } from \"../../lib/slotContent.js\"\nimport s from \"@plexui/styles/components/FieldGroup/FieldGroup.module.css\"\n\n// Vue port of packages/ui/src/components/FieldGroup/FieldGroup.tsx.\n//\n// - `title` and `description` take a string prop or a slot of the same name,\n// like React's ReactNode props. `action` and `footer` are slots here.\n// - Attributes reach the root `section`, as React's rest props do.\n\nconst FieldGroupComponent = defineComponent({\n name: \"FieldGroup\",\n inheritAttrs: false,\n props: {\n /** Heading over the block (or the `title` slot); it names the group */\n title: String,\n /** Line under the title (or the `description` slot) */\n description: String,\n /** Class for the block that holds the rows */\n bodyClass: [String, Array, Object] as PropType<ClassValue>,\n },\n slots: Object as SlotsType<{\n /** The rows: `Field row`, or rows of your own. */\n default?: () => VNodeChild\n title?: () => VNodeChild\n description?: () => VNodeChild\n /** Content at the end of the header, such as a button */\n action?: () => VNodeChild\n /** Content under the block, such as a note */\n footer?: () => VNodeChild\n }>,\n setup(props, { attrs, slots }) {\n const titleId = `field-group-${useId()}`\n\n return () => {\n const title = slots.title ? slots.title() : props.title\n const hasTitle = slots.title ? hasContent(title as VNodeArrayChildren) : !!title\n const description = slots.description ? slots.description() : props.description\n const hasDescription = slots.description ? hasContent(description as VNodeArrayChildren) : !!description\n const action = slots.action?.()\n const hasAction = !!action && hasContent(action as VNodeArrayChildren)\n\n return h(\n \"section\",\n {\n \"role\": \"group\",\n \"aria-labelledby\": hasTitle ? titleId : undefined,\n ...attrs,\n \"class\": clsx(s.FieldGroup, attrs.class as ClassValue),\n },\n [\n hasTitle || hasDescription || hasAction\n ? h(\"div\", { class: s.Header }, [\n h(\"div\", { class: s.HeaderText }, [\n hasTitle ? h(\"h2\", { class: s.Title, id: titleId }, [title as VNodeChild]) : null,\n hasDescription ? h(\"p\", { class: s.Description }, [description as VNodeChild]) : null,\n ]),\n hasAction ? action : null,\n ])\n : null,\n h(\"div\", { class: clsx(s.Body, props.bodyClass) }, [slots.default?.()]),\n slots.footer?.(),\n ],\n )\n }\n },\n})\n\ntype FieldGroupOwnProps = InstanceType<typeof FieldGroupComponent>[\"$props\"]\n\n/** FieldGroup props; attributes reach the root element. */\nexport type FieldGroupProps = FieldGroupOwnProps & { class?: ClassValue }\n\n/** A titled block of rows: `Field row` lines with hairlines between them. */\nexport const FieldGroup = FieldGroupComponent as typeof FieldGroupComponent & { new (): { $props: FieldGroupProps } }\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/FieldGroup/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAiB,CAAA","sourcesContent":["export { FieldGroup, type FieldGroupProps } from \"./FieldGroup.js\"\n"]}
|
|
@@ -28,10 +28,12 @@ declare const FieldComponent: import("vue").DefineComponent<import("vue").Extrac
|
|
|
28
28
|
type: BooleanConstructor;
|
|
29
29
|
default: boolean;
|
|
30
30
|
};
|
|
31
|
-
/** Layout direction of label and control. @default "vertical" */
|
|
32
|
-
orientation:
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
/** Layout direction of label and control. @default "horizontal" on a `row`, else "vertical" */
|
|
32
|
+
orientation: PropType<"vertical" | "horizontal">;
|
|
33
|
+
/** One line of a FieldGroup: label at the start, control at the end. @default false */
|
|
34
|
+
row: {
|
|
35
|
+
type: BooleanConstructor;
|
|
36
|
+
default: boolean;
|
|
35
37
|
};
|
|
36
38
|
/** Overrides the generated id set on the control and the label's `for`. A child's own `id` wins over both. */
|
|
37
39
|
id: StringConstructor;
|
|
@@ -58,10 +60,12 @@ declare const FieldComponent: import("vue").DefineComponent<import("vue").Extrac
|
|
|
58
60
|
type: BooleanConstructor;
|
|
59
61
|
default: boolean;
|
|
60
62
|
};
|
|
61
|
-
/** Layout direction of label and control. @default "vertical" */
|
|
62
|
-
orientation:
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
/** Layout direction of label and control. @default "horizontal" on a `row`, else "vertical" */
|
|
64
|
+
orientation: PropType<"vertical" | "horizontal">;
|
|
65
|
+
/** One line of a FieldGroup: label at the start, control at the end. @default false */
|
|
66
|
+
row: {
|
|
67
|
+
type: BooleanConstructor;
|
|
68
|
+
default: boolean;
|
|
65
69
|
};
|
|
66
70
|
/** Overrides the generated id set on the control and the label's `for`. A child's own `id` wins over both. */
|
|
67
71
|
id: StringConstructor;
|
|
@@ -69,7 +73,7 @@ declare const FieldComponent: import("vue").DefineComponent<import("vue").Extrac
|
|
|
69
73
|
opticallyAlign: PropType<"start" | "end">;
|
|
70
74
|
}>> & Readonly<{}>, {
|
|
71
75
|
required: boolean;
|
|
72
|
-
|
|
76
|
+
row: boolean;
|
|
73
77
|
}, SlotsType<{
|
|
74
78
|
/** The control. Read the props to render them yourself (React's render prop). */
|
|
75
79
|
default?: (fieldProps: FieldChildProps) => VNodeChild;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ClassValue } from "clsx";
|
|
2
|
+
import { type PropType, type SlotsType, type VNodeChild } from "vue";
|
|
3
|
+
declare const FieldGroupComponent: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
4
|
+
/** Heading over the block (or the `title` slot); it names the group */
|
|
5
|
+
title: StringConstructor;
|
|
6
|
+
/** Line under the title (or the `description` slot) */
|
|
7
|
+
description: StringConstructor;
|
|
8
|
+
/** Class for the block that holds the rows */
|
|
9
|
+
bodyClass: PropType<ClassValue>;
|
|
10
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
13
|
+
/** Heading over the block (or the `title` slot); it names the group */
|
|
14
|
+
title: StringConstructor;
|
|
15
|
+
/** Line under the title (or the `description` slot) */
|
|
16
|
+
description: StringConstructor;
|
|
17
|
+
/** Class for the block that holds the rows */
|
|
18
|
+
bodyClass: PropType<ClassValue>;
|
|
19
|
+
}>> & Readonly<{}>, {}, SlotsType<{
|
|
20
|
+
/** The rows: `Field row`, or rows of your own. */
|
|
21
|
+
default?: () => VNodeChild;
|
|
22
|
+
title?: () => VNodeChild;
|
|
23
|
+
description?: () => VNodeChild;
|
|
24
|
+
/** Content at the end of the header, such as a button */
|
|
25
|
+
action?: () => VNodeChild;
|
|
26
|
+
/** Content under the block, such as a note */
|
|
27
|
+
footer?: () => VNodeChild;
|
|
28
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
29
|
+
type FieldGroupOwnProps = InstanceType<typeof FieldGroupComponent>["$props"];
|
|
30
|
+
/** FieldGroup props; attributes reach the root element. */
|
|
31
|
+
export type FieldGroupProps = FieldGroupOwnProps & {
|
|
32
|
+
class?: ClassValue;
|
|
33
|
+
};
|
|
34
|
+
/** A titled block of rows: `Field row` lines with hairlines between them. */
|
|
35
|
+
export declare const FieldGroup: typeof FieldGroupComponent & {
|
|
36
|
+
new (): {
|
|
37
|
+
$props: FieldGroupProps;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FieldGroup, type FieldGroupProps } from "./FieldGroup.js";
|