diff --git a/documentation/storybook.md b/documentation/storybook.md index 6e3b9804f3..774e42c975 100644 --- a/documentation/storybook.md +++ b/documentation/storybook.md @@ -31,10 +31,20 @@ A guideline on how to use the prop may be added, as well as a description of its Prevent mentioning the component’s name in a prop description – that should be obvious. Prop types that aren’t exported don’t require their properties to be described. +### Args + +Add [`args`](https://storybook.js.org/docs/react/writing-stories/args) to the Story to set initial values for props. +Follow these guidelines: + +1. For Boolean props, set their default value to `false`, + unless this has side effects e.g. rendering a class name. + In that case, don’t specify a value. + Storybook will then display a button ‘Set boolean’ that show a switch. + ### Arg Types Add [`argTypes`](https://storybook.js.org/docs/api/arg-types) to the Story to document native HTML attributes or override the generated controls. -Be sure to follow these guidelines when you do: +Follow these guidelines: 1. Add a `description` field instead of a JSDoc comment for native HTML attributes. Use terse sentences that end with a full stop. diff --git a/packages/css/src/components/icon-button/icon-button.scss b/packages/css/src/components/icon-button/icon-button.scss index 7a7de250b4..86b484dab7 100644 --- a/packages/css/src/components/icon-button/icon-button.scss +++ b/packages/css/src/components/icon-button/icon-button.scss @@ -30,31 +30,31 @@ @include reset; } -.ams-icon-button--on-background-light { - color: var(--ams-icon-button-on-background-light-color); +.ams-icon-button--contrast-color { + color: var(--ams-icon-button-contrast-color-color); &:hover { - background-color: var(--ams-icon-button-on-background-light-hover-background-color); - color: var(--ams-icon-button-on-background-light-hover-color); + background-color: var(--ams-icon-button-contrast-color-hover-background-color); + color: var(--ams-icon-button-contrast-color-hover-color); } &:disabled { background-color: transparent; - color: var(--ams-icon-button-on-background-light-disabled-color); + color: var(--ams-icon-button-contrast-color-disabled-color); } } -.ams-icon-button--on-background-dark { - background-color: var(--ams-icon-button-on-background-dark-background-color); - color: var(--ams-icon-button-on-background-dark-color); +.ams-icon-button--inverse-color { + background-color: var(--ams-icon-button-inverse-color-background-color); + color: var(--ams-icon-button-inverse-color-color); &:hover { - background-color: var(--ams-icon-button-on-background-dark-hover-background-color); - color: var(--ams-icon-button-on-background-dark-hover-color); + background-color: var(--ams-icon-button-inverse-color-hover-background-color); + color: var(--ams-icon-button-inverse-color-hover-color); } &:disabled { - background-color: var(--ams-icon-button-on-background-dark-disabled-background-color); - color: var(--ams-icon-button-on-background-dark-disabled-color); + background-color: var(--ams-icon-button-inverse-color-disabled-background-color); + color: var(--ams-icon-button-inverse-color-disabled-color); } } diff --git a/packages/css/src/components/link-list/link-list.scss b/packages/css/src/components/link-list/link-list.scss index 8df908b4fe..fd03d56739 100644 --- a/packages/css/src/components/link-list/link-list.scss +++ b/packages/css/src/components/link-list/link-list.scss @@ -53,18 +53,18 @@ @include hyphenation; } -.ams-link-list__link--on-background-dark { - color: var(--ams-link-list-link-on-background-dark-color); +.ams-link-list__link--contrast-color { + color: var(--ams-link-list-link-contrast-color-color); &:hover { - color: var(--ams-link-list-link-on-background-dark-hover-color); + color: var(--ams-link-list-link-contrast-color-hover-color); } } -.ams-link-list__link--on-background-light { - color: var(--ams-link-list-link-on-background-light-color); +.ams-link-list__link--inverse-color { + color: var(--ams-link-list-link-inverse-color-color); &:hover { - color: var(--ams-link-list-link-on-background-light-hover-color); + color: var(--ams-link-list-link-inverse-color-hover-color); } } diff --git a/packages/css/src/components/link/link.scss b/packages/css/src/components/link/link.scss index f959cde9cb..5a24f51e8b 100644 --- a/packages/css/src/components/link/link.scss +++ b/packages/css/src/components/link/link.scss @@ -50,26 +50,26 @@ } } -.ams-link--on-background-dark { - color: var(--ams-link-on-background-dark-color); +.ams-link--contrast-color { + color: var(--ams-link-contrast-color-color); &:hover { - color: var(--ams-link-on-background-dark-hover-color); + color: var(--ams-link-contrast-color-hover-color); } &:visited { - color: var(--ams-link-on-background-dark-visited-color); + color: var(--ams-link-contrast-color-visited-color); } } -.ams-link--on-background-light { - color: var(--ams-link-on-background-light-color); +.ams-link--inverse-color { + color: var(--ams-link-inverse-color-color); &:hover { - color: var(--ams-link-on-background-light-hover-color); + color: var(--ams-link-inverse-color-hover-color); } &:visited { - color: var(--ams-link-on-background-light-visited-color); + color: var(--ams-link-inverse-color-visited-color); } } diff --git a/packages/react/src/IconButton/IconButton.test.tsx b/packages/react/src/IconButton/IconButton.test.tsx index 2e8be603a4..3d0c53ef93 100644 --- a/packages/react/src/IconButton/IconButton.test.tsx +++ b/packages/react/src/IconButton/IconButton.test.tsx @@ -37,20 +37,20 @@ describe('Icon button', () => { expect(component).toBeInTheDocument() }) - it('renders the right on background light class', () => { - render() + it('renders the class name for contrast color', () => { + render() const component = screen.getByRole('button') - expect(component).toHaveClass('ams-icon-button--on-background-light') + expect(component).toHaveClass('ams-icon-button--contrast-color') }) - it('renders the right on background dark class', () => { - render() + it('renders the class name for inverse color', () => { + render() const component = screen.getByRole('button') - expect(component).toHaveClass('ams-icon-button--on-background-dark') + expect(component).toHaveClass('ams-icon-button--inverse-color') }) it('supports ForwardRef in React', () => { diff --git a/packages/react/src/IconButton/IconButton.tsx b/packages/react/src/IconButton/IconButton.tsx index 0a6045ccff..a5b12d3ed6 100644 --- a/packages/react/src/IconButton/IconButton.tsx +++ b/packages/react/src/IconButton/IconButton.tsx @@ -12,8 +12,10 @@ import { Icon } from '../Icon' export type IconButtonProps = { /** The accessible text for the button. Will be announced by screen readers. Should describe the button’s action. */ label: string - /** Describes the underlying background colour. Allows the icon to provide visual contrast. */ - onBackground?: 'light' | 'dark' + /** Changes the text colour for readability on a light (but not white) background. */ + contrastColor?: boolean + /** Changes the text colour for readability on a dark background. */ + inverseColor?: boolean /** The size of the icon. Corresponds with the text levels. */ size?: 'level-3' | 'level-4' | 'level-5' | 'level-6' /** The component rendering the icon’s markup. */ @@ -22,7 +24,7 @@ export type IconButtonProps = { export const IconButton = forwardRef( ( - { className, label, onBackground, size = 'level-5', svg = CloseIcon, ...restProps }: IconButtonProps, + { className, label, contrastColor, inverseColor, size = 'level-5', svg = CloseIcon, ...restProps }: IconButtonProps, ref: ForwardedRef, ) => (