Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(list): add OrderedDisplayList component (#3835)
* feat(list): add OrderedDisplayList * chore: pr fixes * chore: update type-docs * chore: fix lint * fix: make list item number semiBold
- Loading branch information
Showing
13 changed files
with
2,172 additions
and
128 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,9 @@ | ||
--- | ||
"@twilio-paste/codemods": minor | ||
"@twilio-paste/list": minor | ||
"@twilio-paste/core": minor | ||
--- | ||
|
||
[List] add `OrderedDisplayList`, `OrderedDisplayListItem`, and `OrderedDisplayListHeading` components. | ||
|
||
These new components provide a visually enhanced numbered list to improve the scannability of sequential steps. |
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
57 changes: 57 additions & 0 deletions
57
packages/paste-core/components/list/src/display/OrderedDisplayList.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,57 @@ | ||
import { Box } from "@twilio-paste/box"; | ||
import { css, styled } from "@twilio-paste/styling-library"; | ||
import { safelySpreadTextProps } from "@twilio-paste/text"; | ||
import * as React from "react"; | ||
|
||
import type { OrderedDisplayListProps, OrderedDisplayListVariants } from "../types"; | ||
import { OrderedDisplayListContext } from "./OrderedDisplayListContext"; | ||
|
||
const GapStyles = { | ||
heading20: "space100", | ||
heading30: "space90", | ||
heading40: "space80", | ||
heading50: "space70", | ||
heading60: "space60", | ||
}; | ||
|
||
const StyledOrderedList = styled(Box)(({ variant }: { variant: OrderedDisplayListVariants }) => { | ||
return css({ | ||
counterReset: "list-counter", | ||
margin: "space0", | ||
padding: "space0", | ||
listStyle: "none", | ||
display: "grid", | ||
gap: GapStyles[variant], | ||
}); | ||
}); | ||
|
||
export const OrderedDisplayList = React.forwardRef<HTMLOListElement, OrderedDisplayListProps>( | ||
( | ||
{ | ||
children, | ||
element = "ORDERED_DISPLAY_LIST", | ||
marginTop, | ||
marginBottom = "space70", | ||
variant = "heading30", | ||
...props | ||
}, | ||
ref, | ||
) => { | ||
return ( | ||
<OrderedDisplayListContext.Provider value={{ variant }}> | ||
<StyledOrderedList | ||
{...safelySpreadTextProps(props)} | ||
as="ol" | ||
element={element} | ||
marginTop={marginTop} | ||
marginBottom={marginBottom} | ||
ref={ref} | ||
variant={variant} | ||
> | ||
{children} | ||
</StyledOrderedList> | ||
</OrderedDisplayListContext.Provider> | ||
); | ||
}, | ||
); | ||
OrderedDisplayList.displayName = "OrderedDisplayList"; |
9 changes: 9 additions & 0 deletions
9
packages/paste-core/components/list/src/display/OrderedDisplayListContext.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,9 @@ | ||
import * as React from "react"; | ||
|
||
import type { OrderedDisplayListVariants } from "../types"; | ||
|
||
interface OrderedDisplayListState { | ||
variant: OrderedDisplayListVariants; | ||
} | ||
|
||
export const OrderedDisplayListContext = React.createContext<OrderedDisplayListState>({ variant: "heading30" }); |
19 changes: 19 additions & 0 deletions
19
packages/paste-core/components/list/src/display/OrderedDisplayListHeading.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,19 @@ | ||
import { Heading } from "@twilio-paste/heading"; | ||
import * as React from "react"; | ||
|
||
import type { OrderedDisplayListHeadingProps } from "../types"; | ||
import { OrderedDisplayListContext } from "./OrderedDisplayListContext"; | ||
|
||
export const OrderedDisplayListHeading = React.forwardRef<HTMLHeadingElement, OrderedDisplayListHeadingProps>( | ||
({ children, element = "ORDERED_DISPLAY_LIST_HEADING", as = "div", ...props }, ref) => { | ||
const { variant } = React.useContext(OrderedDisplayListContext); | ||
|
||
return ( | ||
<Heading {...props} ref={ref} as={as} variant={variant} element={element} marginBottom="space0"> | ||
{children} | ||
</Heading> | ||
); | ||
}, | ||
); | ||
|
||
OrderedDisplayListHeading.displayName = "OrderedDisplayListHeading"; |
Oops, something went wrong.