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 lists to appear in white on a dark background #1074

Merged
merged 19 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
9cda129
Inverse color classes and token
dlnr Feb 12, 2024
5e1bc98
Nested lists fix
dlnr Feb 12, 2024
5a2d119
Update packages/css/src/components/ordered-list/ordered-list.scss
dlnr Feb 13, 2024
7498a48
Update packages/react/src/OrderedList/OrderedList.tsx
dlnr Feb 13, 2024
2066450
Update packages/react/src/UnorderedList/UnorderedList.tsx
dlnr Feb 13, 2024
f4d158e
Update packages/react/src/UnorderedList/UnorderedList.tsx
dlnr Feb 13, 2024
f7d5e56
Update packages/react/src/UnorderedList/UnorderedList.tsx
dlnr Feb 13, 2024
0fea88f
Update packages/react/src/OrderedList/OrderedList.tsx
dlnr Feb 13, 2024
fa92a92
Update packages/css/src/components/unordered-list/unordered-list.scss
dlnr Feb 13, 2024
1039c45
Update packages/css/src/components/ordered-list/ordered-list.scss
dlnr Feb 13, 2024
81b011b
Merge branch 'develop' of https://github.com/Amsterdam/design-system …
dlnr Feb 13, 2024
10885f0
InverseColor stories
dlnr Feb 13, 2024
6e74b03
InverseColor stories and remove option to make all stories white
dlnr Feb 13, 2024
a836146
Merge branch 'develop' of https://github.com/Amsterdam/design-system …
dlnr Feb 13, 2024
dec6023
Deleted line fix
dlnr Feb 13, 2024
8916bef
Copy `inverseColor` docs exactly from other components
VincentSmedinga Feb 13, 2024
7fb41b5
Move decorators to the only stories that use it
VincentSmedinga Feb 13, 2024
2e785cd
Merge branch 'develop' into feature/DES-610-inverse-color-lists
VincentSmedinga Feb 19, 2024
0f36714
Propagate args to nested list
VincentSmedinga Feb 19, 2024
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
4 changes: 4 additions & 0 deletions packages/css/src/components/ordered-list/ordered-list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
}
}

.amsterdam-ordered-list--inverse-color:not(.amsterdam-ordered-list--no-markers) {
color: var(--amsterdam-ordered-list-inverse-color);
}

/** A nested list has a different marker and less indentation for correct alignment. */
:is(.amsterdam-ordered-list, .amsterdam-unordered-list) .amsterdam-ordered-list {
list-style-type: var(--amsterdam-ordered-list-ordered-list-list-style-type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
}
}

.amsterdam-unordered-list--inverse-color:not(.amsterdam-unordered-list--no-markers) {
color: var(--amsterdam-unordered-list-inverse-color);
}

/** A nested list has a different marker and less indentation for correct alignment. */
:is(.amsterdam-ordered-list, .amsterdam-unordered-list) .amsterdam-unordered-list {
list-style-type: var(--amsterdam-unordered-list-unordered-list-list-style-type);
Expand Down
13 changes: 11 additions & 2 deletions packages/react/src/OrderedList/OrderedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@ import { OrderedListItem } from './OrderedListItem'

export type OrderedListProps = {
markers?: boolean
inverseColor?: boolean
} & PropsWithChildren<OlHTMLAttributes<HTMLOListElement>>

type OrderedListComponent = {
Item: typeof OrderedListItem
} & ForwardRefExoticComponent<OrderedListProps & RefAttributes<HTMLOListElement>>

export const OrderedList = forwardRef(
({ children, markers = true, className, ...restProps }: OrderedListProps, ref: ForwardedRef<HTMLOListElement>) => (
(
{ children, className, inverseColor, markers = true, ...restProps }: OrderedListProps,
ref: ForwardedRef<HTMLOListElement>,
) => (
<ol
ref={ref}
className={clsx('amsterdam-ordered-list', !markers && 'amsterdam-ordered-list--no-markers', className)}
className={clsx(
'amsterdam-ordered-list',
inverseColor && 'amsterdam-ordered-list--inverse-color',
!markers && 'amsterdam-ordered-list--no-markers',
className,
)}
{...restProps}
>
{children}
Expand Down
13 changes: 11 additions & 2 deletions packages/react/src/UnorderedList/UnorderedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { ForwardedRef, ForwardRefExoticComponent, HTMLAttributes, PropsWith
import { UnorderedListItem } from './UnorderedListItem'

export type UnorderedListProps = {
inverseColor?: boolean
markers?: boolean
} & PropsWithChildren<HTMLAttributes<HTMLUListElement>>

Expand All @@ -17,11 +18,19 @@ type UnorderedListComponent = {
} & ForwardRefExoticComponent<UnorderedListProps & RefAttributes<HTMLUListElement>>

export const UnorderedList = forwardRef(
({ children, markers = true, className, ...restProps }: UnorderedListProps, ref: ForwardedRef<HTMLUListElement>) => {
(
{ children, className, inverseColor, markers = true, ...restProps }: UnorderedListProps,
ref: ForwardedRef<HTMLUListElement>,
) => {
return (
<ul
ref={ref}
className={clsx('amsterdam-unordered-list', !markers && 'amsterdam-unordered-list--no-markers', className)}
className={clsx(
'amsterdam-unordered-list',
inverseColor && 'amsterdam-unordered-list--inverse-color',
!markers && 'amsterdam-unordered-list--no-markers',
className,
)}
{...restProps}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"font-size": { "value": "{amsterdam.typography.text-level.5.font-size}" },
"font-weight": { "value": "{amsterdam.typography.font-weight.normal}" },
"gap": { "value": "0.75rem" },
"inverse-color": { "value": "{amsterdam.color.primary-white}" },
"line-height": { "value": "{amsterdam.typography.text-level.5.line-height}" },
"list-style-type": { "value": "decimal" },
"item": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"font-size": { "value": "{amsterdam.typography.text-level.5.font-size}" },
"font-weight": { "value": "{amsterdam.typography.font-weight.normal}" },
"gap": { "value": "0.75rem" },
"inverse-color": { "value": "{amsterdam.color.primary-white}" },
"line-height": { "value": "{amsterdam.typography.text-level.5.line-height}" },
"list-style-type": { "value": "'\\2022'" },
"item": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,11 @@ Therefore, it does not define typography for the items.
For example, here are three news articles:

<Canvas of={OrderedListStories.WithoutMarkers} />

### Inverse colour

Set the `inverseColor` prop if the List sits on a dark background.
This ensures the colour of the text provides enough contrast.
When nesting lists, set the prop on all lists.

<Canvas of={OrderedListStories.InverseColor} />
13 changes: 13 additions & 0 deletions storybook/storybook-react/src/OrderedList/OrderedList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,16 @@ export const WithoutMarkers: Story = {
markers: false,
},
}

export const InverseColor: Story = {
args: {
inverseColor: true,
VincentSmedinga marked this conversation as resolved.
Show resolved Hide resolved
},
decorators: [
(Story, context) => (
<div className={context.args.inverseColor ? 'amsterdam-docs-dark-background' : undefined}>
<Story />
</div>
),
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import README from "../../../../packages/css/src/components/unordered-list/READM
<Meta of={UnorderedListStories} />

<Markdown>{README}</Markdown>

## Examples

### Default
Expand Down Expand Up @@ -35,3 +36,11 @@ Therefore, this variant does not define typography for the items.
This example is based on the top tasks on the homepage of the website:

<Canvas of={UnorderedListStories.WithoutMarkers} />

### Inverse colour

Set the `inverseColor` prop if the List sits on a dark background.
This ensures the colour of the text provides enough contrast.
When nesting lists, set the prop on all lists.

<Canvas of={UnorderedListStories.InverseColor} />
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,16 @@ export const WithoutMarkers: Story = {
markers: false,
},
}

export const InverseColor: Story = {
args: {
inverseColor: true,
},
decorators: [
(Story, context) => (
<div className={context.args.inverseColor ? 'amsterdam-docs-dark-background' : undefined}>
<Story />
</div>
),
],
}
Loading