-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
## Summary: This PR get us closer to prepare form field components to apply a future Polaris theme. - Generated `All Variant` stories for Checkbox and Radio components. - Migrated `color` instances to use `semanticColor` in `Checkbox` and `Radio`. **NOTE:** Next PR will do the same for the remaining form fields (`TextField`, `TextArea`). Issue: WB-1814 ## Test plan: Verify that the Checkbox and Radio stories look correct Author: jandrade Reviewers: beaesguerra, jandrade Required Reviewers: Approved By: beaesguerra Checks: ✅ Chromatic - Get results on regular PRs (ubuntu-latest, 20.x), ✅ Test / Test (ubuntu-latest, 20.x, 2/2), ✅ Test / Test (ubuntu-latest, 20.x, 1/2), ✅ Lint / Lint (ubuntu-latest, 20.x), ✅ Check build sizes (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Chromatic - Build and test on regular PRs / chromatic (ubuntu-latest, 20.x), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 20.x), ⏭️ Chromatic - Skip on Release PR (changesets), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ gerald, ⏭️ dependabot Pull Request URL: #2439
- Loading branch information
Showing
16 changed files
with
401 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/wonder-blocks-tokens": minor | ||
--- | ||
|
||
Add `icon.disabled` token to semanticColor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/wonder-blocks-form": patch | ||
--- | ||
|
||
Migrate Radio and Checkbox to use semanticColor tokens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import * as React from "react"; | ||
import type {StrictArgs} from "@storybook/react"; | ||
|
||
import {StyleSheet} from "aphrodite"; | ||
import {addStyle} from "@khanacademy/wonder-blocks-core"; | ||
import { | ||
border, | ||
semanticColor, | ||
spacing, | ||
} from "@khanacademy/wonder-blocks-tokens"; | ||
|
||
import {LabelLarge} from "@khanacademy/wonder-blocks-typography"; | ||
|
||
const StyledTable = addStyle("table"); | ||
const StyledTh = addStyle("th"); | ||
const StyledTd = addStyle("td"); | ||
|
||
type Variant = {name: string; props: StrictArgs}; | ||
|
||
type Props = { | ||
/** | ||
* The children as a function that receives the state props used to render | ||
* each variant of the component. | ||
*/ | ||
children: (props: any) => React.ReactNode; | ||
/** | ||
* The categories to display in the table as columns. | ||
*/ | ||
rows: Array<Variant>; | ||
/** | ||
* The states to display in the table as rows. | ||
*/ | ||
columns: Array<Variant>; | ||
}; | ||
|
||
/** | ||
* A table that displays all possible variants of a component. | ||
*/ | ||
export function AllVariants({children, columns, rows}: Props) { | ||
return ( | ||
<StyledTable style={styles.table}> | ||
<thead> | ||
<tr> | ||
<StyledTh style={styles.cell}> | ||
<LabelLarge>Category / State</LabelLarge> | ||
</StyledTh> | ||
{columns.map((col, index) => ( | ||
<StyledTh key={index} scope="col" style={styles.cell}> | ||
<LabelLarge>{col.name}</LabelLarge> | ||
</StyledTh> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{rows.map((row, idx) => ( | ||
<tr key={idx}> | ||
<StyledTd scope="row" style={styles.cell}> | ||
<LabelLarge>{row.name}</LabelLarge> | ||
</StyledTd> | ||
{columns.map((col) => ( | ||
<StyledTd | ||
key={col.name} | ||
style={[ | ||
styles.cell, | ||
{ | ||
border: `${border.width.hairline}px dashed ${semanticColor.border.primary}`, | ||
}, | ||
]} | ||
> | ||
{children({ | ||
...row.props, | ||
...col.props, | ||
})} | ||
</StyledTd> | ||
))} | ||
</tr> | ||
))} | ||
</tbody> | ||
</StyledTable> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
table: { | ||
borderCollapse: "collapse", | ||
textAlign: "left", | ||
}, | ||
cell: { | ||
margin: spacing.medium_16, | ||
padding: spacing.medium_16, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as React from "react"; | ||
import type {Meta, StoryObj} from "@storybook/react"; | ||
|
||
import {Checkbox} from "@khanacademy/wonder-blocks-form"; | ||
|
||
import {AllVariants} from "../components/all-variants"; | ||
|
||
const rows = [ | ||
{name: "Unchecked", props: {checked: false}}, | ||
{name: "Checked", props: {checked: true}}, | ||
{name: "Indeterminate", props: {checked: null}}, | ||
]; | ||
|
||
const columns = [ | ||
{ | ||
name: "Default", | ||
props: {}, | ||
}, | ||
{ | ||
name: "Disabled", | ||
props: {disabled: true}, | ||
}, | ||
{ | ||
name: "Error", | ||
props: {error: true}, | ||
}, | ||
]; | ||
|
||
type Story = StoryObj<typeof Checkbox>; | ||
|
||
/** | ||
* The following stories are used to generate the pseudo states for the Checkbox | ||
* component. This is only used for visual testing in Chromatic. | ||
*/ | ||
const meta = { | ||
title: "Packages / Form / Checkbox / Checkbox - All Variants", | ||
component: Checkbox, | ||
render: (args) => ( | ||
<AllVariants rows={rows} columns={columns}> | ||
{(props) => <Checkbox {...args} {...props} />} | ||
</AllVariants> | ||
), | ||
args: { | ||
label: "Label", | ||
description: "Description", | ||
}, | ||
tags: ["!autodocs"], | ||
} satisfies Meta<typeof Checkbox>; | ||
|
||
export default meta; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Hover: Story = { | ||
parameters: {pseudo: {hover: true}}, | ||
}; | ||
|
||
export const Focus: Story = { | ||
parameters: {pseudo: {focusVisible: true}}, | ||
}; | ||
|
||
export const HoverFocus: Story = { | ||
name: "Hover + Focus", | ||
parameters: {pseudo: {hover: true, focusVisible: true}}, | ||
}; | ||
|
||
export const Active: Story = { | ||
parameters: {pseudo: {active: true}}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import * as React from "react"; | ||
import type {Meta, StoryObj} from "@storybook/react"; | ||
|
||
// NOTE: Radio is an internal component and should not be used directly. Use | ||
// RadioGroup instead. This import is only used for visual testing in Chromatic. | ||
import Radio from "../../packages/wonder-blocks-form/src/components/radio"; | ||
|
||
import {AllVariants} from "../components/all-variants"; | ||
|
||
const rows = [ | ||
{name: "Unchecked", props: {checked: false}}, | ||
{name: "Checked", props: {checked: true}}, | ||
]; | ||
|
||
const columns = [ | ||
{ | ||
name: "Default", | ||
props: {}, | ||
}, | ||
{ | ||
name: "Disabled", | ||
props: {disabled: true}, | ||
}, | ||
{ | ||
name: "Error", | ||
props: {error: true}, | ||
}, | ||
]; | ||
|
||
type Story = StoryObj<typeof Radio>; | ||
|
||
/** | ||
* The following stories are used to generate the pseudo states for the Radio | ||
* component. This is only used for visual testing in Chromatic. | ||
*/ | ||
const meta = { | ||
title: "Packages / Form / Radio (internal) / Radio - All Variants", | ||
component: Radio, | ||
render: (args) => ( | ||
<AllVariants rows={rows} columns={columns}> | ||
{(props) => <Radio {...args} {...props} />} | ||
</AllVariants> | ||
), | ||
args: { | ||
label: "Label", | ||
description: "Description", | ||
}, | ||
tags: ["!autodocs"], | ||
} satisfies Meta<typeof Radio>; | ||
|
||
export default meta; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const Hover: Story = { | ||
parameters: {pseudo: {hover: true}}, | ||
}; | ||
|
||
export const Focus: Story = { | ||
parameters: {pseudo: {focusVisible: true}}, | ||
}; | ||
|
||
export const HoverFocus: Story = { | ||
name: "Hover + Focus", | ||
parameters: {pseudo: {hover: true, focusVisible: true}}, | ||
}; | ||
|
||
export const Active: Story = { | ||
parameters: {pseudo: {active: true}}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.