Skip to content

Commit

Permalink
chore: Modal, Dialog, Popup and Toast Styles Refactor (#2795)
Browse files Browse the repository at this point in the history
Fixes: #2773  

Styles refactor for Modal, Dialog and Popup.

[category:Components]

Release Note:
Updated `Modal, Dialog, Popup and Toast` to use new `system` tokens and style utilities.
  • Loading branch information
josh-bagwell authored Jul 19, 2024
1 parent 066c4b1 commit 92573a5
Show file tree
Hide file tree
Showing 20 changed files with 459 additions and 266 deletions.
151 changes: 151 additions & 0 deletions modules/docs/mdx/12.0-UPGRADE-GUIDE.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import {Meta} from '@storybook/addon-docs';
import {Table} from '@workday/canvas-kit-react/table';
import {base, brand, system} from '@workday/canvas-tokens-web';
import {StatusIndicator} from '@workday/canvas-kit-preview-react/status-indicator';
import {cssVar} from '@workday/canvas-kit-styling';
import {Box} from '@workday/canvas-kit-react/layout';

<Meta title="Guides/Upgrade Guides/v12.0" />

# Canvas Kit 12.0 Upgrade Guide
Expand All @@ -8,10 +15,58 @@ any questions.

## Why You Should Upgrade

Canvas Kit v12 is transitioning into a
[new way of styling](https://github.com/Workday/canvas-kit/discussions/2265). Theming and building
an in sync Canvas Kit CSS has been at the top of our minds. We've started using our new
[Canvas Tokens Web](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)
package to take advantage of
[CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties) and
provide semantic tokens that can translate to theming components.

A note to the reader:

- While we still support our old tokens from `@workday/canvas-kit-react/tokens` in v12, you must
install our new tokens from `@workday/canvas-tokens-web`. You can find more info in our
[docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).
- In this release, we've introduced a
[new styling API](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-stencil).
This shouldn't effect the way you currently style your components. Because we're moving away from
Emotion, support for style props will eventually be removed, however, this API provide backwards
compatability. If you want to slowly move off of Emotion as well, you can start styling components
via the `cs` prop or our new styling utilities.

## Table of contents

- [Canvas Tokens](#canvas-tokens)
- [Codemod](#codemod)
- [Deprecations](#deprecations)
- [Removals](#removals)
- [Select (Preview)](#select-preview)
- [Component Updates](#component-updates)
- [Popup, Dialog and Modal](#popup-dialog-and-modal)
- [Toast](#toast)
- [Style Utility Updates](#style-utility-updates)
- [createStencil](#createstencil)
- [Troubleshooting](#troubleshooting)
- [Glossary](#glossary)
- [Main](#main)
- [Preview](#preview)
- [Labs](#labs)

## Canvas Tokens

In v12, all the components listed in this guide have started using our new
[Canvas Tokens Web](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).

In v12 you must add `@workday/canvas-tokens-web` to ensure our components are properly styled and the
variables are defined. For more information on installing and using, please reference our tokens
[docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs).

## Deprecations

We add the [@deprecated](https://jsdoc.app/tags-deprecated.html) JSDoc tag to code we plan to remove
in a future major release. This signals consumers to migrate to a more stable alternative before the
deprecated code is removed.

## Removals
Removals are deletions from our codebase and you can no longer consume this component. We've either promoted or replaced a component or utility.
Expand All @@ -21,3 +76,99 @@ Removals are deletions from our codebase and you can no longer consume this comp
**PR:** [#2796](https://github.com/Workday/canvas-kit/pull/2796)

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).

---

## Component Updates

### Styling API and CSS Tokens

Several components have been refactored to use our new
[Canvas Tokens](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs) and
[styling API](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--create-modifiers#createstyles-api).
The React interface **has not changed**, but CSS variables are now used for dynamic properties.

The following components are affected:

- `Popup`
- `Dialog`
- `Modal`
- `Toast`

> **Note:** These components also support our new `cs` prop for styling. Learn more about styling
> with `cs` in our
> [documentation](https://workday.github.io/canvas-kit/?path=/docs/styling-basics--cs-prop).
### Popup, Dialog and Modal

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

### Toast

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

## Style Utility Updates

## Troubleshooting

### My Styles Seem Broken?

Our components are reliant on our new Canvas Tokens Web package. Be sure you install
`@workday/canvas-tokens-web`. For more information, reference our
[Getting Started docs](https://workday.github.io/canvas-tokens/?path=/docs/docs-getting-started--docs)
for this package.

### Did You Upgrade All Canvas Kit Related Packages?

In order for all the packages to work in harmony, you must upgrade all Canvas Kit packages to the
same version that you're using, including:

- `@workday/canvas-kit-react`
- `@workday/canvas-kit-preview-react`
- `@workday/canvas-kit-labs-react`
- `@workday/canvas-kit-styling`
- `@workday/canvas-kit-react-fonts`
- `@workday/canvas-kit-docs`

## Glossary

### Main

Our Main package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-react` has
undergone a full design and a11y review and is approved for use in product.

Breaking changes to code in Main will only occur during major version updates and will always be
communicated in advance and accompanied by migration strategies.

---

### Preview

Our Preview package of Canvas Kit tokens, components, and utilities at
`@workday/canvas-kit-preview-react` has undergone a full design and a11y review and is approved for
use in product, but may not be up to the high code standards upheld in the [Main](#main) package.
Preview is analagous to code in beta.

Breaking changes are unlikely, but possible, and can be deployed to Preview at any time without
triggering a major version update, though such changes will be communicated in advance and
accompanied by migration strategies.

Generally speaking, our goal is to eventually promote code from Preview to [Main](#main).
Occasionally, a component with the same name will exist in both [Main](#main) and Preview (for
example, see Segmented Control in [Preview](/components/buttons/segmented-control/) and
[Main](https://d2krrudi3mmzzw.cloudfront.net/v8/?path=/docs/components-buttons-segmented-control--basic)).
In these cases, Preview serves as a staging ground for an improved version of the component with a
different API. The component in [Main](#main) will eventually be replaced with the one in Preview.

---

### Labs

Our Labs package of Canvas Kit tokens, components, and utilities at `@workday/canvas-kit-labs-react`
has **not** undergone a full design and a11y review. Labs serves as an incubator space for new and
experimental code and is analagous to code in alpha.

Breaking changes can be deployed to Labs at any time without triggering a major version update and
may not be subject to the same rigor in communcation and migration strategies reserved for breaking
changes in [Preview](#preview) and [Main](#main). import { opacity } from
"@workday/canvas-tokens-web/dist/es6/system"
24 changes: 22 additions & 2 deletions modules/react/common/lib/utils/getTranslateFromOrigin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {CanvasSpaceValues} from '@workday/canvas-kit-react/tokens';
import {TransformOrigin} from '../types';
import {calc} from '@workday/canvas-kit-styling';

type translateMapType = {
x: {[key in TransformOrigin['horizontal']]: number};
Expand All @@ -24,13 +25,32 @@ const translateMap: translateMapType = {
* @param {Object} transformOrigin The origin of the transform (i.e. top left)
* @param {string} distance The distance to translate (as a canvas spacing value).
* @returns {Object} An object with the x and y distance values needed to translate.
* @deprecated
*/

export const getTranslateFromOrigin = (
transformOrigin: TransformOrigin,
distance: CanvasSpaceValues
) => {
const calculatedDistance = parseFloat(distance) * 16;
return {
x: translateMap.x[transformOrigin.horizontal] * calculatedDistance,
y: translateMap.y[transformOrigin.vertical] * calculatedDistance,
};
};

/**
* Gets the x and y distance values needed to translate from a given transform origin to 0,0
* @param {Object} transformOrigin The origin of the transform (i.e. top left)
* @param {string} distance The distance to translate (as a canvas spacing value).
* @returns {Object} An object with the x and y distance string values needed to translate.
*/
export const getTransformOrigin = (
transformOrigin: TransformOrigin,
distance: CanvasSpaceValues | (string & {})
) => {
return {
x: translateMap.x[transformOrigin.horizontal] * parseInt(distance, 10),
y: translateMap.y[transformOrigin.vertical] * parseInt(distance, 10),
x: calc.multiply(distance, translateMap.x[transformOrigin.horizontal]),
y: calc.multiply(distance, translateMap.y[transformOrigin.vertical]),
};
};
3 changes: 2 additions & 1 deletion modules/react/icon/lib/SystemIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export interface SystemIconStyles {
/**
* The hover color of the SystemIcon. This defines `accentHover` and `fillHover`. `colorHover` may be overwritten by `accentHover` and `fillHover`.
* @default base.licorice200
* @deprecated `colorHover` is deprecated and will be removed in a future version. Please use the following instead in your style overrides:
* @deprecated `colorHover` is deprecated and will be removed in a future version. We have removed the default hover styles on SystemIcon. Please
* use the following instead in your style overrides:
* ```tsx
* '&:hover': {
* [systemIconStencil.vars.color]: desiredColorHoverColor
Expand Down
27 changes: 11 additions & 16 deletions modules/react/modal/lib/ModalBody.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
import * as React from 'react';

import {
createSubcomponent,
ExtractProps,
getTheme,
styled,
StyledType,
} from '@workday/canvas-kit-react/common';
import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common';
import {Popup} from '@workday/canvas-kit-react/popup';
import {space} from '@workday/canvas-kit-react/tokens';

import {useModalModel} from './hooks';
import {createStencil} from '@workday/canvas-kit-styling';
import {system} from '@workday/canvas-tokens-web';
import {mergeStyles} from '@workday/canvas-kit-react/layout';

export interface ModalBodyProps extends ExtractProps<typeof Popup.Body, never> {}

const ResponsiveModalBody = styled(Popup.Body)<ModalBodyProps & StyledType>(({theme}) => {
const {canvas: canvasTheme} = getTheme(theme);
return {
[canvasTheme.breakpoints.down('s')]: {
marginBottom: space.zero,
padding: `${space.xxxs} ${space.xxs} ${space.xxs} ${space.xxs}`,
export const modalBodyStencil = createStencil({
base: {
'@media screen and (max-width: 768px)': {
marginBlockEnd: system.space.zero,
padding: `${system.space.x1} ${system.space.x2} ${system.space.x2}`,
},
};
},
});

export const ModalBody = createSubcomponent('div')({
displayName: 'Modal.Body',
modelHook: useModalModel,
})<ModalBodyProps>((elemProps, Element) => {
return <ResponsiveModalBody as={Element} {...elemProps} />;
return <Popup.Body as={Element} {...mergeStyles(elemProps, modalBodyStencil())} />;
});
34 changes: 16 additions & 18 deletions modules/react/modal/lib/ModalCard.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import * as React from 'react';

import {
createSubcomponent,
ExtractProps,
StyledType,
styled,
getTheme,
} from '@workday/canvas-kit-react/common';
import {space} from '@workday/canvas-kit-react/tokens';
import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common';
import {Popup} from '@workday/canvas-kit-react/popup';

import {useModalCard, useModalModel} from './hooks';
import {calc, createStencil} from '@workday/canvas-kit-styling';
import {system} from '@workday/canvas-tokens-web';
import {mergeStyles} from '@workday/canvas-kit-react/layout';

export interface ModalCardProps extends ExtractProps<typeof Popup.Card, never> {}

const ResponsiveModalCard = styled(Popup.Card)<ModalCardProps & StyledType>(({theme}) => {
const {canvas: canvasTheme} = getTheme(theme);
return {
margin: space.xl,
[canvasTheme.breakpoints.down('s')]: {
margin: space.s, // 16px all around margin on smaller screen sizes
padding: space.s, // brings total padding between edge and content to 24px
borderRadius: space.m, // 24px border radius on smaller devices.
export const modalCardStencil = createStencil({
base: {
margin: system.space.x10,
width: calc.add(calc.multiply(system.space.x20, 5), system.space.x10),
borderWidth: system.space.zero,
boxShadow: system.depth[6],
'@media screen and (max-width: 768px)': {
margin: system.space.x4, // 16px all around margin on smaller screen sizes
padding: system.space.x4, // brings total padding between edge and content to 24px
borderRadius: system.space.x6, // 24px border radius on smaller devices.
},
};
},
});

export const ModalCard = createSubcomponent('div')({
displayName: 'Modal.Card',
modelHook: useModalModel,
elemPropsHook: useModalCard,
})<ModalCardProps>((elemProps, Element) => {
return <ResponsiveModalCard as={Element} width={440} borderWidth={0} depth={6} {...elemProps} />;
return <Popup.Card as={Element} {...mergeStyles(elemProps, modalCardStencil())} />;
});
27 changes: 11 additions & 16 deletions modules/react/modal/lib/ModalHeading.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
import * as React from 'react';

import {
createSubcomponent,
ExtractProps,
getTheme,
styled,
StyledType,
} from '@workday/canvas-kit-react/common';
import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common';
import {Popup} from '@workday/canvas-kit-react/popup';
import {space} from '@workday/canvas-kit-react/tokens';

import {useModalHeading, useModalModel} from './hooks';
import {createStencil} from '@workday/canvas-kit-styling';
import {system} from '@workday/canvas-tokens-web';
import {mergeStyles} from '@workday/canvas-kit-react/layout';

export interface ModalHeadingProps extends ExtractProps<typeof Popup.Heading, never> {}

const ResponsiveModalHeading = styled(Popup.Heading)<ModalHeadingProps & StyledType>(({theme}) => {
const {canvas: canvasTheme} = getTheme(theme);
return {
[canvasTheme.breakpoints.down('s')]: {
marginBottom: space.zero,
padding: `${space.xxs} ${space.xxs} ${space.xxxs} ${space.xxs}`,
export const modalHeadingStencil = createStencil({
base: {
'@media screen and (max-width: 768px)': {
marginBlockEnd: system.space.zero,
padding: `${system.space.x2} ${system.space.x2} ${system.space.x1}`,
},
};
},
});

export const ModalHeading = createSubcomponent('h2')({
displayName: 'Modal.Heading',
modelHook: useModalModel,
elemPropsHook: useModalHeading,
})<ModalHeadingProps>((elemProps, Element) => {
return <ResponsiveModalHeading as={Element} {...elemProps} />;
return <Popup.Heading as={Element} {...mergeStyles(elemProps, modalHeadingStencil())} />;
});
14 changes: 9 additions & 5 deletions modules/react/modal/lib/ModalOverflowOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import * as React from 'react';

import {createSubcomponent, ExtractProps, StyledType} from '@workday/canvas-kit-react/common';
import {createSubcomponent, ExtractProps} from '@workday/canvas-kit-react/common';

import {ModalOverlay} from './ModalOverlay';
import styled from '@emotion/styled';
import {useModalModel} from './hooks';
import {createStencil} from '@workday/canvas-kit-styling';
import {mergeStyles} from '@workday/canvas-kit-react/layout';

const StyledOverlay = styled(ModalOverlay)<StyledType>({
'& > div': {maxHeight: 'inherit'}, // reset maxHeight of centering div
export const modalOverflowOverlayStencil = createStencil({
base: {
'& > div': {maxHeight: 'inherit'}, // reset maxHeight of centering div
overflow: 'hidden auto',
},
});

export const ModalOverflowOverlay = createSubcomponent('div')({
displayName: 'Modal.OverflowOverlay',
modelHook: useModalModel,
})<ExtractProps<typeof ModalOverlay, never>>((elemProps, Element) => {
return <StyledOverlay as={Element} overflowX="hidden" overflowY="auto" {...elemProps} />;
return <ModalOverlay as={Element} {...mergeStyles(elemProps, modalOverflowOverlayStencil())} />;
});
Loading

0 comments on commit 92573a5

Please sign in to comment.