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: Update checkbox to use system color tokens #2683

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
25 changes: 17 additions & 8 deletions modules/react/checkbox/lib/CheckBackground.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as React from 'react';
import {createComponent, ErrorType} from '@workday/canvas-kit-react/common';
import {calc, createStencil, createVars, px2rem, cssVar} from '@workday/canvas-kit-styling';
import {base, brand, system} from '@workday/canvas-tokens-web';
import {brand, system} from '@workday/canvas-tokens-web';

interface CheckBackgroundProps {
children: React.ReactNode;
error?: ErrorType;
}

export const backgroundVars = createVars('inner', 'outer');
export const checkboxStatusColorVars = createVars('inner', 'outer');
RayRedGoose marked this conversation as resolved.
Show resolved Hide resolved

const checkboxBackgroundStencil = createStencil({
base: {
RayRedGoose marked this conversation as resolved.
Show resolved Hide resolved
alignItems: 'center',
backgroundColor: base.frenchVanilla100,
backgroundColor: system.color.bg.default,
borderRadius: system.shape.half,
boxSizing: 'border-box',
display: 'flex',
Expand All @@ -24,17 +24,26 @@ const checkboxBackgroundStencil = createStencil({
position: 'absolute',
transition: 'border 200ms ease, background 200ms',
width: calc.add(system.space.x4, px2rem(2)),
border: `${px2rem(1)} solid ${base.licorice200}`,
border: `${px2rem(1)} solid ${system.color.fg.muted.soft}`,
josh-bagwell marked this conversation as resolved.
Show resolved Hide resolved
RayRedGoose marked this conversation as resolved.
Show resolved Hide resolved
},
modifiers: {
error: {
error: {
[backgroundVars.inner]: cssVar(brand.error.base, base.cinnamon500),
[backgroundVars.outer]: 'transparent',
[checkboxStatusColorVars.inner]: cssVar(
brand.error.base,
system.color.border.critical.default
),
[checkboxStatusColorVars.outer]: 'transparent',
},
alert: {
[backgroundVars.inner]: cssVar(brand.alert.base, base.cantaloupe600),
[backgroundVars.outer]: cssVar(brand.alert.darkest, base.cantaloupe400),
[checkboxStatusColorVars.inner]: cssVar(
brand.alert.base,
system.color.border.caution.strong
),
[checkboxStatusColorVars.outer]: cssVar(
brand.alert.darkest,
system.color.border.caution.default
),
},
},
},
Expand Down
38 changes: 19 additions & 19 deletions modules/react/checkbox/lib/CheckboxCheck.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import {ErrorType, createComponent} from '@workday/canvas-kit-react/common';
import {createStencil, createStyles, cssVar, calc, px2rem} from '@workday/canvas-kit-styling';
import {createStencil, cssVar, calc, px2rem} from '@workday/canvas-kit-styling';
import {brand, system} from '@workday/canvas-tokens-web';
import {SystemIcon} from '@workday/canvas-kit-react/icon';
import {SystemIcon, systemIconStencil} from '@workday/canvas-kit-react/icon';
import {checkSmallIcon} from '@workday/canvas-system-icons-web';
import {CheckBackground} from './CheckBackground';

Expand All @@ -24,36 +24,43 @@ const checkboxCheckStencil = createStencil({
marginInlineStart: calc.negate(px2rem(6)),
transition: 'margin 200ms ease',
},
opacity: 0,
opacity: system.opacity.zero,
transform: 'scale(0.5)',
},
modifiers: {
checked: {
true: {
opacity: 1,
[systemIconStencil.vars.color]: cssVar(brand.primary.accent, system.color.icon.inverse),
opacity: system.opacity.full,
transform: 'scale(1)',
},
},
indeterminate: {
true: {
opacity: 1,
opacity: system.opacity.full,
transform: 'scale(1)',
},
},
variant: {
inverse: {
[systemIconStencil.vars.color]: cssVar(
brand.primary.base,
system.color.icon.primary.default
),
'& > div': {
backgroundColor: brand.primary.base,
backgroundColor: cssVar(brand.primary.base, system.color.bg.primary.default),
},
},
},
},
});

const indeterminateBoxStyles = createStyles({
width: calc.add(system.space.x2, px2rem(2)),
height: calc.divide(system.space.x1, 2),
backgroundColor: brand.primary.accent,
const indeterminateBoxStencil = createStencil({
base: {
width: px2rem(10),
josh-bagwell marked this conversation as resolved.
Show resolved Hide resolved
height: calc.divide(system.space.x1, 2),
backgroundColor: cssVar(brand.primary.accent, system.color.bg.default),
},
});

export const CheckboxCheck = createComponent('div')({
Expand All @@ -63,16 +70,9 @@ export const CheckboxCheck = createComponent('div')({
<CheckBackground error={error}>
<div {...checkboxCheckStencil({checked, indeterminate, variant})}>
{indeterminate ? (
<div className={indeterminateBoxStyles} />
<div {...indeterminateBoxStencil()} />
) : (
checked && (
<SystemIcon
icon={checkSmallIcon}
color={
variant === 'inverse' ? cssVar(brand.primary.base) : cssVar(brand.primary.accent)
}
/>
)
checked && <SystemIcon icon={checkSmallIcon} />
)}
</div>
</CheckBackground>
Expand Down
44 changes: 22 additions & 22 deletions modules/react/checkbox/lib/CheckboxContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import {createComponent} from '@workday/canvas-kit-react/common';
import {CSProps, calc, createStyles, cssVar, px2rem, createVars} from '@workday/canvas-kit-styling';
import {CSProps, calc, createStencil, cssVar, px2rem} from '@workday/canvas-kit-styling';
import {system} from '@workday/canvas-tokens-web';
import {LabelText} from '@workday/canvas-kit-react/text';

Expand All @@ -12,35 +12,35 @@ interface CheckboxContainerProps extends CSProps {
variant?: 'inverse';
}

export const inputVars = createVars('errorInner', 'errorOuter', 'alertInner', 'alertOuter');
RayRedGoose marked this conversation as resolved.
Show resolved Hide resolved

const checkboxContainerStyles = createStyles({
display: 'flex',
alignItems: 'center',
minHeight: system.space.x6,
position: 'relative',
/**
* Using a wrapper prevents the browser default behavior of trigging
* :hover on the checkbox when you hover on it's corresponding label.
* This stops the ripple from showing when you hover on the label.
*/
'&>div': {
const checkboxContainerStencil = createStencil({
base: {
display: 'flex',
height: calc.add(system.space.x4, px2rem(2)),
minWidth: calc.add(system.space.x4, px2rem(2)),
marginTop: px2rem(3),
alignSelf: 'flex-start',
},
'& > label': {
paddingInlineStart: cssVar(system.space.x3),
alignItems: 'center',
minHeight: system.space.x6,
position: 'relative',
/**
* Using a wrapper prevents the browser default behavior of trigging
* :hover on the checkbox when you hover on it's corresponding label.
* This stops the ripple from showing when you hover on the label.
*/
'&>div': {
display: 'flex',
height: calc.add(system.space.x4, px2rem(2)),
minWidth: calc.add(system.space.x4, px2rem(2)),
marginTop: px2rem(3),
alignSelf: 'flex-start',
},
'& > label': {
paddingInlineStart: cssVar(system.space.x3),
},
},
});

export const CheckboxContainer = createComponent('div')({
displayName: 'CheckboxContainer',
Component: ({children, disabled, id, label, variant}: CheckboxContainerProps) => {
return (
<div className={checkboxContainerStyles}>
<div {...checkboxContainerStencil()}>
<div>{children}</div>
{label && (
<LabelText
Expand Down
Loading
Loading