@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
44 lines (43 loc) • 2.57 kB
JavaScript
import React from 'react';
import { createSubcomponent, accessibleHide } 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 { useFormFieldLabel, useFormFieldModel } from './hooks';
export const formFieldLabelStencil = createStencil({
extends: textStencil,
// @ts-ignore Still weird about CSS font variables
base: { name: "d5h44d", 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: "d5h44e", 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: {
horizontalStart: { name: "d5h44f", styles: "justify-content:flex-start;float:left;max-height:var(--cnvs-sys-space-x10);" },
horizontalEnd: { name: "d5h44g", styles: "max-height:var(--cnvs-sys-space-x10);float:left;justify-content:flex-end;" },
vertical: { name: "d5h44h", styles: "width:100%;" }
},
isHidden: {
true: { name: "d5h44i", styles: "clip:rect(1px, 1px, 1px, 1px);clip-path:polygon(0px 0px, 0px 0px, 0px 0px, 0px 0px);position:absolute;overflow:hidden;white-space:nowrap;height:1px;min-height:1px;width:1px;min-width:1px;margin:-1px;padding:0;border:0;" }
}
},
defaultModifiers: {
typeLevel: 'subtext.large',
}
}, "form-field-label-7bb465");
export const FormFieldLabel = createSubcomponent('label')({
displayName: 'FormField.Label',
modelHook: useFormFieldModel,
elemPropsHook: useFormFieldLabel,
})(({ children, typeLevel, variant, isHidden, ...elemProps }, Element, model) => {
return (React.createElement(Element, { ...mergeStyles(elemProps, formFieldLabelStencil({
typeLevel,
variant,
isHidden: isHidden ? 'true' : undefined,
isRequired: model.state.isRequired,
orientation: model.state.orientation === 'horizontal'
? 'horizontalStart'
: model.state.orientation,
})) }, children));
});