-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Heading and Text components (#510)
* implement RAC Text * scaffolding Text docs * WIP on implementing BCDS typescale * React Aria library update to 1.5.0 * Add Accordion and AccordionGroup components (#499) * staging Accordion and AccordionGroup file structure * bump RAC to 1.4.0 * basic shape of Accordion component * tweak props import * add story wireframe for Accordion * styling accordion * styling * additional styling and alternative icon implementation * refining button styling * scaffolding AccordionGroup * add title prop and styling to AccordionGroup * continuing work on Accordion and AccordionGroup styling * fix focus state for accordions inside accordiongroup * fleshing out argTypes * scaffolding accordion docs * add examples to vite kitchen sink * fleshing out examples on vite * expanding stories and docs * stories and docs * typo * renaming CSS classes to bcds-react-aria-* to match convention * typo * add comments to accordion group props * remove unused CSS class * bump RAC to 1.5.0 * update RAC imports * Refactor Select to use ListBoxSection (#504) * bump RAC to 1.5.0 * replace Section with ListBoxSection * Revert "bump RAC to 1.5.0" This reverts commit 75e05e7. * Reapply "bump RAC to 1.5.0" This reverts commit 0edc443. * storybook library update to 8.4.7 * add TextProps, refining styling * add missing CSS import * fork Heading styles into new component * add vite page for dev and testing * demo content * add text colour prop * wireframing storybook docs * add isUnstyled prop to Heading and Text * docs and stories * add color prop to Heading and flesh out docs * add ARIA attribute to fix accessibility violation * add explicit default elementType * add missing elementType declaration * docs edits --------- Co-authored-by: Arora <Supriya.Arora@gov.bc.ca> Co-authored-by: Supriya-Arora <101464129+Supriya-Arora@users.noreply.github.com>
- Loading branch information
1 parent
a1698ed
commit 87b4d0f
Showing
15 changed files
with
587 additions
and
0 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
44 changes: 44 additions & 0 deletions
44
packages/react-components/src/components/Heading/Heading.css
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,44 @@ | ||
/* Headings */ | ||
h1.bcds-react-aria-Heading { | ||
font: var(--typography-bold-h1); | ||
} | ||
|
||
h2.bcds-react-aria-Heading { | ||
font: var(--typography-bold-h2); | ||
} | ||
|
||
h3.bcds-react-aria-Heading { | ||
font: var(--typography-bold-h3); | ||
} | ||
|
||
h4.bcds-react-aria-Heading { | ||
font: var(--typography-bold-h4); | ||
} | ||
|
||
h5.bcds-react-aria-Heading { | ||
font: var(--typography-bold-h5); | ||
} | ||
|
||
h6.bcds-react-aria-Heading { | ||
font: var(--typography-bold-h6); | ||
} | ||
|
||
/* Text colour */ | ||
.bcds-react-aria-Heading.primary { | ||
color: var(--typography-color-primary); | ||
} | ||
.bcds-react-aria-Heading.primaryInvert { | ||
color: var(--typography-color-primary-invert); | ||
} | ||
.bcds-react-aria-Heading.secondary { | ||
color: var(--typography-color-secondary); | ||
} | ||
.bcds-react-aria-Heading.secondaryInvert { | ||
color: var(--typography-color-secondary-invert); | ||
} | ||
.bcds-react-aria-Heading.disabled { | ||
color: var(--typography-color-disabled); | ||
} | ||
.bcds-react-aria-Heading.danger { | ||
color: var(--typography-color-danger); | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/react-components/src/components/Heading/Heading.tsx
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,32 @@ | ||
import { | ||
Heading as ReactAriaHeading, | ||
HeadingProps as ReactAriaHeadingProps, | ||
} from "react-aria-components"; | ||
|
||
import "./Heading.css"; | ||
|
||
export interface HeadingProps extends ReactAriaHeadingProps { | ||
/* Sets text color, defaults to primary */ | ||
color?: | ||
| "primary" | ||
| "primaryInvert" | ||
| "secondary" | ||
| "secondaryInvert" | ||
| "disabled" | ||
| "danger"; | ||
/* If true, renders component without CSS class */ | ||
isUnstyled?: boolean; | ||
} | ||
|
||
export default function Heading({ | ||
color = "primary", | ||
isUnstyled = false, | ||
...props | ||
}: HeadingProps) { | ||
return ( | ||
<ReactAriaHeading | ||
className={isUnstyled ? undefined : `bcds-react-aria-Heading ${color}`} | ||
{...props} | ||
/> | ||
); | ||
} |
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,2 @@ | ||
export { default } from "./Heading"; | ||
export type { HeadingProps } from "./Heading"; |
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,64 @@ | ||
/* Medium size (default) */ | ||
.bcds-react-aria-Text.medium { | ||
font: var(--typography-regular-body); | ||
} | ||
|
||
.bcds-react-aria-Text.medium b, | ||
.bcds-react-aria-Text.medium strong { | ||
font: var(--typography-bold-body); | ||
} | ||
|
||
.bcds-react-aria-Text.medium i, | ||
.bcds-react-aria-Text.medium em { | ||
font: var(--typography-italic-body); | ||
} | ||
|
||
/* Small size */ | ||
.bcds-react-aria-Text.small { | ||
font: var(--typography-regular-small-body); | ||
} | ||
|
||
.bcds-react-aria-Text.small b, | ||
.bcds-react-aria-Text.small strong { | ||
font: var(--typography-bold-small-body); | ||
} | ||
|
||
.bcds-react-aria-Text.small i, | ||
.bcds-react-aria-Text.small em { | ||
font: var(--typography-italic-small-body); | ||
} | ||
|
||
/* Large size */ | ||
.bcds-react-aria-Text.large { | ||
font: var(--typography-regular-large-body); | ||
} | ||
|
||
.bcds-react-aria-Text.large b, | ||
.bcds-react-aria-Text.large strong { | ||
font: var(--typography-bold-large-body); | ||
} | ||
|
||
.bcds-react-aria-Text.large i, | ||
.bcds-react-aria-Text.large em { | ||
font: var(--typography-italic-large-body); | ||
} | ||
|
||
/* Text color */ | ||
.bcds-react-aria-Text.primary { | ||
color: var(--typography-color-primary); | ||
} | ||
.bcds-react-aria-Text.primaryInvert { | ||
color: var(--typography-color-primary-invert); | ||
} | ||
.bcds-react-aria-Text.secondary { | ||
color: var(--typography-color-secondary); | ||
} | ||
.bcds-react-aria-Text.secondaryInvert { | ||
color: var(--typography-color-secondary-invert); | ||
} | ||
.bcds-react-aria-Text.disabled { | ||
color: var(--typography-color-disabled); | ||
} | ||
.bcds-react-aria-Text.danger { | ||
color: var(--typography-color-danger); | ||
} |
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,41 @@ | ||
import { | ||
Text as ReactAriaText, | ||
TextProps as ReactAriaTextProps, | ||
} from "react-aria-components"; | ||
|
||
import "./Text.css"; | ||
|
||
export interface TextProps extends ReactAriaTextProps { | ||
/* Sets text size, defaults to medium */ | ||
size?: "small" | "medium" | "large"; | ||
/* Sets text color, defaults to primary */ | ||
color?: | ||
| "primary" | ||
| "primaryInvert" | ||
| "secondary" | ||
| "secondaryInvert" | ||
| "disabled" | ||
| "danger"; | ||
/* If true, renders component without CSS class */ | ||
isUnstyled?: boolean; | ||
} | ||
|
||
export default function Text({ | ||
elementType = "span", | ||
size = "medium", | ||
color = "primary", | ||
isUnstyled = false, | ||
...props | ||
}: TextProps) { | ||
return ( | ||
<ReactAriaText | ||
elementType={elementType} | ||
className={ | ||
isUnstyled ? undefined : `bcds-react-aria-Text ${size} ${color}` | ||
} | ||
{...props} | ||
> | ||
{props.children} | ||
</ReactAriaText> | ||
); | ||
} |
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,2 @@ | ||
export { default } from "./Text"; | ||
export type { TextProps } from "./Text"; |
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,55 @@ | ||
import { Heading, Text } from "@/components"; | ||
|
||
export default function TextPage() { | ||
return ( | ||
<> | ||
<Heading level={2}>Headings and text</Heading> | ||
<Text> | ||
The Heading and Text components provide an easy way to populate sections | ||
of content. They implement the B.C. Design System's typescale. | ||
</Text> | ||
<Heading level={3}>Headings</Heading> | ||
<Text> | ||
The Heading component supports standard HTML heading levels (H1 to H6). | ||
</Text> | ||
<Heading level={3}>Text size</Heading> | ||
<Text>The text component supports 3 different sizes: </Text> | ||
<ul> | ||
<li> | ||
<Text size="large">Large</Text> | ||
</li> | ||
<li> | ||
<Text size="medium">Medium (default)</Text> | ||
</li> | ||
<li> | ||
<Text size="small">Small</Text> | ||
</li> | ||
</ul> | ||
<Heading level={4}>Text styling</Heading> | ||
<Text> | ||
The text component also supports standard text styling, like <b>bold</b>{" "} | ||
and <i>italic</i>. | ||
</Text> | ||
<Heading level={4}>Text colour</Heading> | ||
<Text>You can modify the colour of text via prop:</Text> | ||
<ul> | ||
<li> | ||
<Text color="primary">Primary (default)</Text> | ||
</li> | ||
<li> | ||
<Text color="secondary">Secondary</Text> | ||
</li> | ||
<li> | ||
<Text color="disabled">Disabled</Text> | ||
</li> | ||
<li> | ||
<Text color="danger">Danger</Text> | ||
</li> | ||
</ul> | ||
<Text> | ||
Inverted versions of the primary and secondary colours for use on dark | ||
backgrounds are also supported. | ||
</Text> | ||
</> | ||
); | ||
} |
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,3 @@ | ||
import TextPage from "./TextPage"; | ||
|
||
export default TextPage; |
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,61 @@ | ||
{/* Heading.mdx */} | ||
|
||
import { | ||
Canvas, | ||
Controls, | ||
Meta, | ||
Primary, | ||
Source, | ||
Story, | ||
Subtitle, | ||
} from "@storybook/blocks"; | ||
|
||
import * as HeadingStories from "./Heading.stories"; | ||
|
||
<Meta of={HeadingStories} /> | ||
|
||
# Headings | ||
|
||
<Subtitle>Utility content for creating section headings</Subtitle> | ||
|
||
<Source | ||
code={`import { Heading } from "@bcgov/design-system-react-components";`} | ||
language="typescript" | ||
/> | ||
|
||
## Usage and resources | ||
|
||
Heading is a utility component that creates a text heading for a section of content. It renders a standard heading element (`<h1>` to `<h6>`), styled to align with the [B.C. Design System typescale](https://www2.gov.bc.ca/gov/content?id=72C2CD6E05494C84B9A072DD9C6A5342). | ||
|
||
## Controls | ||
|
||
<Canvas of={HeadingStories.HeadingTemplate} /> | ||
<Controls of={HeadingStories.HeadingTemplate} /> | ||
|
||
## Configuration | ||
|
||
Heading text is populated via the `children` slot. | ||
|
||
### Styling headings | ||
|
||
You can override the default styling of a heading by either: | ||
|
||
- Passing a `className` to apply your own CSS class | ||
- Setting the `isUnstyled` prop to render a heading without any additional CSS, allowing it to inherit its styles from its parent element | ||
|
||
<Canvas of={HeadingStories.UnstyledHeading} /> | ||
|
||
Use the `color` prop to set the text colour, from the options defined in the design system colour palette: | ||
|
||
<Canvas of={HeadingStories.PrimaryInvert} /> | ||
|
||
### Heading level | ||
|
||
Use the `level` prop to set the heading level. `level` expects a number from 1 to 6: | ||
|
||
<Canvas of={HeadingStories.Heading1} /> | ||
<Canvas of={HeadingStories.Heading2} /> | ||
<Canvas of={HeadingStories.Heading3} /> | ||
<Canvas of={HeadingStories.Heading4} /> | ||
<Canvas of={HeadingStories.Heading5} /> | ||
<Canvas of={HeadingStories.Heading6} /> |
Oops, something went wrong.