Skip to content

Commit

Permalink
fix: Deprecate parentModifier
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel.carrera committed Sep 19, 2024
1 parent 63fc6c5 commit a0c55e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
3 changes: 1 addition & 2 deletions modules/preview-react/form-field/lib/FormFieldGroupLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react';

import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common';
import {createStencil, parentModifier, px2rem} from '@workday/canvas-kit-styling';
import {createStencil, px2rem} from '@workday/canvas-kit-styling';
import {Text, textStencil} from '@workday/canvas-kit-react/text';
import {FlexProps, mergeStyles} from '@workday/canvas-kit-react/layout';
import {brand, system} from '@workday/canvas-tokens-web';

import {useFormFieldLabel, useFormFieldModel} from './hooks';
import {formFieldStencil} from './formFieldStencil';

export interface FormFieldLabelProps
extends FlexProps,
Expand Down
40 changes: 25 additions & 15 deletions modules/preview-react/form-field/lib/FormFieldHint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import React from 'react';

import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common';
import {system, brand} from '@workday/canvas-tokens-web';
import {createStencil, parentModifier} from '@workday/canvas-kit-styling';
import {createStencil} from '@workday/canvas-kit-styling';
import {Text, textStencil} from '@workday/canvas-kit-react/text';
import {mergeStyles} from '@workday/canvas-kit-react/layout';

import {useFormFieldHint, useFormFieldModel} from './hooks';
import {formFieldStencil} from './formFieldStencil';

export const formFieldHintStencil = createStencil({
extends: textStencil,
base: {
margin: `${system.space.x2} ${system.space.zero} ${system.space.zero}`,
[parentModifier(formFieldStencil.modifiers.error.error)]: {
color: brand.error.base,
},
modifiers: {
isRequired: {
true: {
color: brand.error.base,
},
},
},
defaultModifiers: {
Expand All @@ -26,15 +29,22 @@ export const FormFieldHint = createSubcomponent('p')({
displayName: 'FormField.Hint',
modelHook: useFormFieldModel,
elemPropsHook: useFormFieldHint,
})<ExtractProps<typeof Text, never>>(({children, typeLevel, variant, ...elemProps}, Element) => {
if (!children) {
// If there is no hint text just skip rendering
return null;
}
})<ExtractProps<typeof Text, never>>(
({children, typeLevel, variant, ...elemProps}, Element, model) => {
if (!children) {
// If there is no hint text just skip rendering
return null;
}

return (
<Element {...mergeStyles(elemProps, formFieldHintStencil({typeLevel, variant}))}>
{children}
</Element>
);
});
return (
<Element
{...mergeStyles(
elemProps,
formFieldHintStencil({typeLevel, variant, isRequired: model.state.isRequired})
)}
>
{children}
</Element>
);
}
);
1 change: 1 addition & 0 deletions modules/styling/lib/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,7 @@ function combineClassNames(input: (string | undefined)[]): string {
* }
* })
* ```
* @deprecated `parentModifier` is deprecated. While we support compat mode, we can't use `parentModifier`. If consumers pass in a style prop, this will created an unstable hash, breaking this function.
*/
export function parentModifier(value: string) {
return `.${value.replace('css-', 'm')} :where(&)`;
Expand Down

0 comments on commit a0c55e3

Please sign in to comment.