Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add FormFieldGroup component and density example #2865

Merged
merged 80 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
5705d9d
fix: Add density example
Aug 1, 2024
adb7ef3
fix: Add formfield group
Aug 6, 2024
392774a
fix: Clean formfield group
Aug 6, 2024
a7a59af
fix: Add horixontal support
Aug 9, 2024
028a60a
fix: Clean up example
Aug 9, 2024
909fb81
fix: Refactor select styles
Aug 9, 2024
421a1d9
fix: Add docs
Aug 9, 2024
911a3da
fix: Update radio usage
Aug 9, 2024
c909633
fix: Remove onchange
Aug 9, 2024
f9826e8
Merge branch 'prerelease/major' into mc-ff-example
mannycarrera4 Aug 9, 2024
22ff4b4
fix: Remove id from input
Aug 12, 2024
30056ef
Merge branch 'mc-ff-example' of https://github.com/mannycarrera4/canv…
Aug 12, 2024
d1744dc
fix: Handle errors better
Aug 12, 2024
5c4978c
fix: Update form validation
Aug 12, 2024
8ddb470
fix: Add timeout
Aug 13, 2024
d34641f
fix: Clean up jsdocs
Aug 13, 2024
f39b3b8
fix: Update jsdocs
Aug 13, 2024
0e7cb0e
fix: Remove unused stencil
Aug 13, 2024
2b35b03
fix: Update density example
Aug 15, 2024
0af112e
fix: Clean up examples
Aug 15, 2024
a8b1813
fix: Update upgrade guide
Aug 15, 2024
e6af5ad
docs: Add info to upgrade guide
Aug 19, 2024
6060aed
fix: Update cc example
Aug 19, 2024
652ee9f
Update modules/preview-react/form-field/stories/examples/AllFields.tsx
mannycarrera4 Aug 22, 2024
1408c84
Update modules/preview-react/form-field/lib/FormFieldGroup.tsx
mannycarrera4 Aug 22, 2024
f7fad11
Update modules/preview-react/form-field/stories/examples/GroupedInput…
mannycarrera4 Aug 22, 2024
f62eee0
fix: Update merge conflicts
Aug 23, 2024
5f3d829
Merge branch 'mc-ff-example' of https://github.com/mannycarrera4/canv…
Aug 23, 2024
caed8f0
Merge branch 'prerelease/major' into mc-ff-example
mannycarrera4 Aug 27, 2024
27c1186
fix: Update example to new storybook format
Aug 29, 2024
f410b29
Merge branch 'mc-ff-example' of https://github.com/mannycarrera4/canv…
Aug 29, 2024
065a2ff
fix: Add back in grouped inputs story
Aug 29, 2024
428a6f2
fix: Remove duplicate import
Aug 29, 2024
4a71a77
fix: Update typecheck
Aug 29, 2024
808b584
fix: Try to remove flakiness
Aug 29, 2024
cb53c47
Update modules/preview-react/form-field/stories/examples/GroupedInput…
mannycarrera4 Aug 30, 2024
e01f067
Update modules/preview-react/form-field/stories/examples/GroupedInput…
mannycarrera4 Aug 30, 2024
d173780
fix: Clean up data attributes and styling
Sep 4, 2024
0375748
fix: Update density selector
Sep 5, 2024
3e0ca10
fix: Clean up selectors
Sep 6, 2024
0c1f437
fix: Add info around selectors
Sep 6, 2024
dd32dcc
fix: Add formfield field
Sep 6, 2024
fcc318e
fix: Update all examples to use formfield field
Sep 9, 2024
052d9db
fix: Remove themable and update upgrade guide
Sep 9, 2024
f559a7e
fix: Update upgrade guide
Sep 10, 2024
fcc63b2
fix: Add info to upgrade guide
Sep 10, 2024
a9903d6
Merge branch 'prerelease/major' into mc-ff-example
mannycarrera4 Sep 10, 2024
c82a3b5
fix: Update merge conflcits
Sep 12, 2024
844c95e
Merge branch 'mc-ff-example' of https://github.com/mannycarrera4/canv…
Sep 12, 2024
b03ec3f
fix: Update accessibility
Sep 16, 2024
d03b1ec
fix: Update to be formfield label
Sep 16, 2024
9378ba3
fix: Update accessbility
Sep 16, 2024
916625a
Update cypress.config.ts
mannycarrera4 Sep 16, 2024
2665034
Update cypress/component/ActionBar.spec.tsx
mannycarrera4 Sep 17, 2024
e8d3194
fix: Clean up upgrade guide
Sep 17, 2024
242e798
Merge branch 'mc-ff-example' of https://github.com/mannycarrera4/canv…
Sep 17, 2024
9104d57
Merge branch 'prerelease/major' into mc-ff-example
mannycarrera4 Sep 17, 2024
0faf886
fix: Update accessibility and density example
Sep 17, 2024
74c0b42
Merge branch 'mc-ff-example' of https://github.com/mannycarrera4/canv…
Sep 17, 2024
1f3a1f8
fix: Update error text in density example
Sep 17, 2024
361175c
fix: Clean up group
Sep 17, 2024
825aa0b
Update modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx
mannycarrera4 Sep 18, 2024
de5ca8d
Update modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx
mannycarrera4 Sep 18, 2024
febd236
Update modules/preview-react/form-field/lib/FormFieldContainer.tsx
mannycarrera4 Sep 18, 2024
8a0aa0d
Update modules/preview-react/form-field/lib/FormFieldContainer.tsx
mannycarrera4 Sep 18, 2024
e7995a9
Update modules/react/action-bar/stories/examples/Basic.tsx
mannycarrera4 Sep 18, 2024
a38b3b1
Update modules/preview-react/form-field/lib/FormField.tsx
mannycarrera4 Sep 18, 2024
78c672e
fix: Clean up examples
Sep 18, 2024
a73eaf0
Merge branch 'mc-ff-example' of https://github.com/mannycarrera4/canv…
Sep 18, 2024
23e2f63
fix: Clean up styles
Sep 18, 2024
521f102
fix: Clean up styles
Sep 18, 2024
435c858
fix: Remove use of parentModifier
Sep 19, 2024
63fc6c5
fix: Clean up radios
Sep 19, 2024
a0c55e3
fix: Deprecate parentModifier
Sep 19, 2024
255829a
fix: Clean up docs
Sep 19, 2024
9b3ac40
Update modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx
mannycarrera4 Sep 19, 2024
67d90e5
Merge branch 'prerelease/major' into mc-ff-example
mannycarrera4 Sep 19, 2024
f3ba40d
fix: Export the things from index
Sep 19, 2024
af922d1
Merge branch 'mc-ff-example' of https://github.com/mannycarrera4/canv…
Sep 19, 2024
a11e36d
Apply suggestions from code review
mannycarrera4 Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ export default defineConfig({
retries: {
runMode: 2,
},
env: {
NODE_ENV: 'development', // or 'development', 'production', etc.
},

blockHosts: ['cdn.fontawesome.com'],

Expand All @@ -20,7 +17,7 @@ export default defineConfig({
framework: 'react',
bundler: 'webpack',
},
setupNodeEvents(on) {
setupNodeEvents(on, config) {
on('file:preprocessor', webpack());
},
viewportWidth: 1024,
Expand Down
12 changes: 9 additions & 3 deletions cypress/component/Tabs.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,14 @@ describe('Tabs', () => {
context('when [Components/Containers/Tabs, OverflowTabs] story is rendered', () => {
beforeEach(() => {
cy.mount(<OverflowTabs />);
cy.wait(500);
});

it('should pass axe checks', () => {
cy.checkA11y();
cy.checkA11y('[role="tablist"]', {
rules: {
'aria-required-children': {enabled: false},
},
});
});

it('should not show the "More" button', () => {
Expand Down Expand Up @@ -519,7 +522,7 @@ describe('Tabs', () => {
context('when tab list container is only 500px wide', () => {
beforeEach(() => {
cy.findByRole('button', {name: '500px'}).click();
cy.wait(0);
cy.findByRole('button', {name: '500px'}).should('have.attr', 'aria-pressed', 'true');
});

it('should pass axe checks', () => {
Expand Down Expand Up @@ -587,6 +590,7 @@ describe('Tabs', () => {
context('when tab list container is only 360px wide', () => {
beforeEach(() => {
cy.findByRole('button', {name: '360px'}).click();
cy.findByRole('button', {name: '360px'}).should('have.attr', 'aria-pressed', 'true');
});

it('should pass axe checks', () => {
Expand All @@ -613,6 +617,7 @@ describe('Tabs', () => {

context('when the "More" button is clicked', () => {
beforeEach(() => {
cy.findByRole('button', {name: '360px'}).should('have.attr', 'aria-pressed', 'true');
cy.findByRole('button', {name: 'More'}).click();
});

Expand All @@ -629,6 +634,7 @@ describe('Tabs', () => {
context('when tab list container is only 150px wide', () => {
beforeEach(() => {
cy.findByRole('button', {name: '150px'}).click();
cy.findByRole('button', {name: '150px'}).should('have.attr', 'aria-pressed', 'true');
});

it('should pass axe checks', () => {
Expand Down
1 change: 1 addition & 0 deletions cypress/support/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ before(() => {
},
};
});

cy.configureAxe({
rules: [
{id: 'landmark-one-main', enabled: false}, // stories don't require navigation rules
Expand Down
168 changes: 150 additions & 18 deletions modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ A note to the reader:
- [Styling Updates](#styling-updates)
- [Compatability Mode](#compatability-mode)
- [Deprecations](#deprecations)
- [Form Field Container](#form-field-container)
- [Removals](#removals)
- [InputIconContainer](#inputiconcontainer)
- [Select (Preview)](#select-preview)
- [Component Updates](#component-updates)
- [Styling API and CSS Tokens](#styling-api-and-css-tokens)
- [Avatar](#avatar)
- [Select](#select)
- [Form Field](#form-field)
- [Text Area](#text-area)
- [Troubleshooting](#troubleshooting)
Expand Down Expand Up @@ -83,17 +84,38 @@ We add the [@deprecated](https://jsdoc.app/tags-deprecated.html) JSDoc tag to co
in a future major release. This signals consumers to migrate to a more stable alternative before the
deprecated code is removed.

## Removals
### Form Field Container

Removals are deletions from our codebase and you can no longer consume this component. We've either
promoted or replaced a component or utility.
**PR:** [#2865](https://github.com/Workday/canvas-kit/pull/2865)

### Select (Preview)
We've deprecated `FormField.Container`. Please use `FormField.Field` or `FormFieldGroup.Field` for
grouped inputs, this ensures proper label alignment and spacing of inputs and hint text, regardless
of the orientation.

**PR:** [#2796](https://github.com/Workday/canvas-kit/pull/2796)
```tsx
// v11
<FormField>
<FormField.Label>Email</FormField.Label>
<FormField.Container>
<FormField.Input as={TextInput} />
<FormField.Hint>You must provide an email</FormField.Hint>
</FormField.Container>
</FormField>

// v12
<FormField>
<FormField.Label>Email</FormField.Label>
<FormField.Field>
<FormField.Input as={TextInput} />
<FormField.Hint>You must provide an email</FormField.Hint>
</FormField.Field>
</FormField>
```

## Removals

We've removed the `Select` component that was in Preview. Please use the compound
[Select component from Main](https://workday.github.io/canvas-kit/?path=/docs/components-inputs-select--basic).
Removals are deletions from our codebase and you can no longer consume this component. We've either
promoted or replaced a component or utility.

### InputIconContainer

Expand Down Expand Up @@ -123,7 +145,6 @@ The following components are affected:

- `Avatar`
- `Dialog`
- `FormField`
- `Modal`
- `Popup`
- `TextArea`
Expand All @@ -136,6 +157,12 @@ The following components are affected:

### Avatar

**PR** [#2793](https://github.com/Workday/canvas-kit/pull/2793)

Avatar has been updated to use our new
[styling utilities](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-stencil).
The following changes have been made to the API:

- `Avatar.Size` has been deprecated. The `size` prop still accepts `Avatar.Size` in addition to the
following values:
`"extraExtraLarge" | "extraLarge" | "large" | "medium" | "small" | "extraSmall" | (string{})`
Expand All @@ -149,12 +176,16 @@ The following components are affected:

### Form Field

**PR** [#2881](https://github.com/Workday/canvas-kit/pull/2881)
**PRs:** [#2865](https://github.com/Workday/canvas-kit/pull/2865),
[#2881](https://github.com/Workday/canvas-kit/pull/2881)

We've promoted FormField from [Preview](#preview) to [Main](#main). The following changes has been
made to provide more flexibility and better explicit components when using inputs.

The orientation prop on the `FormField` component will be updated to accept the following values:
`vertical`, `horizontalStart`, and `horizontalEnd`. `horizontal` will still be accepted as a value
in v12, but it will be deprecated and slated for removal in a future major release. These changes
are intended to provide more flexibility with label alignments on `FormField` elements.
- The orientation prop on the `FormField` component will be updated to accept the following values:
`vertical`, `horizontalStart`, and `horizontalEnd`. `horizontal` will still be accepted as a value
in v12, but it will be deprecated and slated for removal in a future major release. These changes
are intended to provide more flexibility with label alignments on `FormField` elements.

> **Note**: The horizontal alignment of start and end are relative to its container, meaning start
> and end match the flex property of `flex-start` and `flex-end`. This is especially applicable for
Expand All @@ -163,9 +194,105 @@ are intended to provide more flexibility with label alignments on `FormField` el
> **Note:** Orientation "horizontal" has been deprecated. You will see a console warn message
> suggesting to update your types and usage to `horizontalStart`, `horizontalEnd` or `vertical`.

- `useFormFieldModel`: `orientation` has been added back into `useFormFieldModel`. While we still
support compat mode due to
[style merging issues](https://github.com/Workday/canvas-kit/discussions/2893), having orientation
on the model allows for proper styling of sub components.

- Styles clean up. `FormField.Hint` and `FormField.Label` where using `margin` for spacing. We've
updated styles so that the containing element uses `gap` for proper spacing.

> **Note:** If spacing seems off between the input and hint text, ensure you're using
> `FormField.Field` wrappign your input and hint text.

🤖 The codemod will handle the change of `orientation="horizontal"` to
`orientation="horizontalStart"` if you're using the string literal values.

#### Form Field Group

We've added a new component under `FromField` to allow users to group inputs without worrying about
setting the `as` prop on the `FormField` component.

Use `FormFieldGroup` when you have a group of inputs that need to be associated to one another, like
`RadioGroup` or a group of `Checkbox`'s.

`FormFieldGroup` supports the same props of `FormField`:

- `error`: `"alert" | "error"` Defines the error around the whole group of inputs.
- `orientation`: `"horizontalStart" | "horizontalEnd" | "vertical" | "horizontal" `. Defines the
label placement.
- `isRequired`: `true` Defines if a group like `RadioGroup` is required.

#### FormField Field

We've added a new sub-component to `FormField` and `FormFieldGroup`, `FormField.Field` and
`FormFieldGroup.Field`. This sub-component is meant to ensure that the label is always aligned with
the input regardless of the `orientation`prop's value on`FormField` or `FormFieldGroup`. This
component should replace `FormField.Container` and always be used to ensure proper alignment of the
label and hint text. Our examples have been updated to reflect this.

Although there is no codemod for this change and it's non-breaking, we suggest moving towards adding
this sub-component when using `FormField`. This component also exists on `FormFieldGroup`.

```tsx
<FormField orientation="horizontal">
<FormField.Label>Email</FormField.Label>
<FormField.Field>
<FormField.Input as={TextInput} />
<FormField.Hint>You must provide an email</FormField.Hint>
</FormField.Field>
</FormField>
```

### Select

**PR:** [#2865](https://github.com/Workday/canvas-kit/pull/2865)

As we transition to use our CSS tokens to provide better theming capabilities and our new styling
methods, we're moving away from components extending `Themeable`. `Themeable` has been removed from
`SelectProps.`

If you wish to theme `Select` we suggest using the CanvasProvider to do so.

```tsx
const theme: PartialEmotionCanvasTheme = {
canvas: {
palette: {
common: {
focusOutline: 'pink',
},
primary: {
main: 'green',
light: 'lightgreen',
},
},
},
};

//...

<CanvasProvider theme={theme}>
<Flex cs={parentContainerStyles}>
<Select items={options}>
<FormField>
<FormField.Label>Contact</FormField.Label>
<FormField.Input as={Select.Input} onChange={handleChange} />
<Select.Popper>
<Select.Card>
<Select.List>
{item => {
return <Select.Item>{item}</Select.Item>;
}}
</Select.List>
</Select.Card>
</Select.Popper>
</FormField>
</Select>
Selected Value: {value}
</Flex>
</CanvasProvider>;
```

### Text Area

**PR:** [#2825](https://github.com/Workday/canvas-kit/pull/2825)
Expand All @@ -176,10 +303,15 @@ type.

```tsx
// v11
interface MyProps { resize?: TextAreaResizeDirection }

// 12 type ValueOf<T> = T[keyof T]; interface MyProps { resize?:
ValueOf<typeof TextAreaResizeDirection> }
interface MyProps {
resize?: TextAreaResizeDirection;
}

// 12
type ValueOf<T> = T[keyof T];
interface MyProps {
resize?: ValueOf<typeof TextAreaResizeDirection>;
}
```

## Troubleshooting
Expand Down
12 changes: 12 additions & 0 deletions modules/preview-react/_examples/stories/mdx/Density.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {ExampleCodeBlock} from '@workday/canvas-kit-docs';
import {Density} from './examples/Density';

<Meta title="Examples/Forms/Density and Alignment" />

# Canvas Kit Density Examples

Although we currently don't support a density system, it's common practice to provide varying
options to users, especially in the context of forms. Below is an example of how you can style our
from elements to achieve the desired density.

<ExampleCodeBlock code={Density} />
Loading
Loading