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

feat: Allow small text for ordered lists #1219

Merged
merged 7 commits into from
May 7, 2024
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
14 changes: 12 additions & 2 deletions packages/css/src/components/ordered-list/ordered-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
.ams-ordered-list:not(.ams-ordered-list--no-markers) {
color: var(--ams-ordered-list-color);
font-family: var(--ams-ordered-list-font-family);
font-size: var(--ams-ordered-list-font-size);
font-size: var(--ams-ordered-list-medium-font-size);
font-weight: var(--ams-ordered-list-font-weight);
line-height: var(--ams-ordered-list-line-height);
line-height: var(--ams-ordered-list-medium-line-height);
list-style-type: var(--ams-ordered-list-list-style-type);

/** List items are responsible for indentation and marker positioning. */
Expand All @@ -38,6 +38,16 @@
}
}

.ams-ordered-list--small:not(.ams-ordered-list--no-markers) {
font-size: var(--ams-ordered-list-small-font-size);
line-height: var(--ams-ordered-list-small-line-height);
}

.ams-ordered-list--large:not(.ams-ordered-list--no-markers) {
font-size: var(--ams-ordered-list-large-font-size);
line-height: var(--ams-ordered-list-large-line-height);
}

.ams-ordered-list--inverse-color:not(.ams-ordered-list--no-markers) {
color: var(--ams-ordered-list-inverse-color);
}
Expand Down
16 changes: 16 additions & 0 deletions packages/react/src/OrderedList/OrderedList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ describe('Ordered list', () => {
expect(items.length).toBe(3)
})

it('renders the small size class', () => {
render(<OrderedList size="small" />)

const component = screen.getByRole('list')

expect(component).toHaveClass('ams-ordered-list--small')
})

it('renders the large size class', () => {
render(<OrderedList size="large" />)

const component = screen.getByRole('list')

expect(component).toHaveClass('ams-ordered-list--large')
})

it('supports ForwardRef in React', () => {
const ref = createRef<HTMLOListElement>()

Expand Down
5 changes: 4 additions & 1 deletion packages/react/src/OrderedList/OrderedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export type OrderedListProps = {
markers?: boolean
/** Changes the text color for readability on a dark background. */
inverseColor?: boolean
/** The size of the ordered list */
size?: 'small' | 'large'
VincentSmedinga marked this conversation as resolved.
Show resolved Hide resolved
} & PropsWithChildren<OlHTMLAttributes<HTMLOListElement>>

const OrderedListRoot = forwardRef(
(
{ children, className, inverseColor, markers = true, ...restProps }: OrderedListProps,
{ children, className, inverseColor, size, markers = true, ...restProps }: OrderedListProps,
ref: ForwardedRef<HTMLOListElement>,
) => (
<ol
Expand All @@ -25,6 +27,7 @@ const OrderedListRoot = forwardRef(
'ams-ordered-list',
inverseColor && 'ams-ordered-list--inverse-color',
!markers && 'ams-ordered-list--no-markers',
size && `ams-ordered-list--${size}`,
className,
)}
{...restProps}
Expand Down
14 changes: 12 additions & 2 deletions proprietary/tokens/src/components/ams/ordered-list.tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
"ordered-list": {
"color": { "value": "{ams.color.primary-black}" },
"font-family": { "value": "{ams.text.font-family}" },
"font-size": { "value": "{ams.text.level.5.font-size}" },
"font-weight": { "value": "{ams.text.font-weight.normal}" },
"gap": { "value": "0.75rem" },
"inverse-color": { "value": "{ams.color.primary-white}" },
"line-height": { "value": "{ams.text.level.5.line-height}" },
"list-style-type": { "value": "decimal" },
"small": {
"font-size": { "value": "{ams.text.level.6.font-size}" },
"line-height": { "value": "{ams.text.level.6.line-height}" }
},
"medium": {
"font-size": { "value": "{ams.text.level.5.font-size}" },
"line-height": { "value": "{ams.text.level.5.line-height}" }
},
VincentSmedinga marked this conversation as resolved.
Show resolved Hide resolved
"large": {
"font-size": { "value": "{ams.text.level.4.font-size}" },
"line-height": { "value": "{ams.text.level.4.line-height}" }
},
"item": {
"margin-inline-start": {
"value": "2.25rem",
Expand Down
12 changes: 12 additions & 0 deletions storybook/src/components/OrderedList/OrderedList.docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ Extra white space between items enhances the distinction, mainly when they consi

<Controls />

## Small

Use a list with a smaller font size in form descriptions and captions and the like.

<Canvas of={OrderedListStories.Small} />

## Large

Use this size only for the introductory text of a page.

<Canvas of={OrderedListStories.Large} />

### Two Levels

A list may have one nested level.
Expand Down
19 changes: 19 additions & 0 deletions storybook/src/components/OrderedList/OrderedList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ const meta = {
argTypes: {
reversed: { control: 'boolean' },
start: { control: 'number' },
size: {
control: {
type: 'radio',
labels: { small: 'small', undefined: 'medium', large: 'large' },
},
options: ['small', undefined, 'large'],
},
},
decorators: [inverseColorDecorator],
} satisfies Meta<typeof OrderedList>
Expand All @@ -35,6 +42,18 @@ type Story = StoryObj<typeof meta>

export const Default: Story = {}

export const Small: Story = {
args: {
size: 'small',
},
}

export const Large: Story = {
args: {
size: 'large',
},
}

export const TwoLevels: Story = {
render: (args) => (
<OrderedList {...args}>
Expand Down
Loading