@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
37 lines (36 loc) • 2.16 kB
JavaScript
import React from 'react';
import { createSubcomponent } from '@workday/canvas-kit-react/common';
import { createStencil, px2rem } from '@workday/canvas-kit-styling';
import { textStencil } from '@workday/canvas-kit-react/text';
import { mergeStyles } from '@workday/canvas-kit-react/layout';
import { brand, system } from '@workday/canvas-tokens-web';
import { useFormFieldModel } from './hooks';
export const formFieldGroupLabelStencil = createStencil({
extends: textStencil,
// @ts-ignore Still weird about CSS font variables
base: { name: "d5h44z", styles: "box-sizing:border-box;font-weight:var(--cnvs-sys-font-weight-medium);color:var(--cnvs-sys-color-text-default);padding-inline-start:var(--cnvs-sys-space-zero);display:flex;align-items:center;min-width:11.25rem;" },
modifiers: {
isRequired: {
true: { name: "d5h450", styles: "&::after{content:\"*\";font-size:var(--cnvs-sys-font-size-body-large);font-weight:var(--cnvs-sys-font-weight-normal);color:var(--cnvs-brand-error-base);text-decoration:unset;margin-inline-start:var(--cnvs-sys-space-x1);}" }
},
orientation: {
vertical: { name: "d5h451", styles: "width:100%;" },
horizontalStart: { name: "d5h452", styles: "justify-content:flex-start;float:left;max-height:var(--cnvs-sys-space-x10);" },
horizontalEnd: { name: "d5h453", styles: "max-height:var(--cnvs-sys-space-x10);float:left;justify-content:flex-end;" }
}
},
defaultModifiers: {
typeLevel: 'subtext.large',
}
}, "form-field-group-label-b84717");
export const FormFieldGroupLabel = createSubcomponent('div')({
displayName: 'FormFieldGroup.Label',
modelHook: useFormFieldModel,
})(({ children, typeLevel, variant, ...elemProps }, Element, model) => {
return (React.createElement(Element, { id: `label-${model.state.id}`, ...mergeStyles(elemProps, formFieldGroupLabelStencil({
typeLevel,
variant,
isRequired: model.state.isRequired,
orientation: model.state.orientation === 'horizontal' ? 'horizontalStart' : model.state.orientation,
})) }, children));
});