-
Notifications
You must be signed in to change notification settings - Fork 366
Use custom properties to change button colours #7269
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
Open
romaricpascal
wants to merge
5
commits into
add-interruption-panel--actions-option
Choose a base branch
from
spike-button-custom-properties
base: add-interruption-panel--actions-option
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
845b19e
Use custom properties to change button colours across variants
romaricpascal d07d5d3
Make Interruption panel style buttons through custom properties
romaricpascal f48e6cb
Use custom properties to style File upload's pseudo button
romaricpascal 886aa05
Use custom properties for warning button colours
romaricpascal ada8799
Add mixin to easily apply button colours
romaricpascal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
packages/govuk-frontend/src/govuk/components/button/_helpers.scss
This file contains hidden or 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,29 @@ | ||
| //// | ||
| /// @group components/button | ||
| //// | ||
|
|
||
| @use "sass:list"; | ||
|
|
||
| /// List of the button variants available in GOV.UK Frontend | ||
| $_available-variants: (secondary, warning, inverse); | ||
|
|
||
| /// Configure colours of the Button component for the given variant | ||
| /// | ||
| /// Use: | ||
| /// - to create modifiers of the `.govuk-button` class to apply a specific variant to a single button | ||
| /// - inside a component to update the default style of all buttons with only the `.govuk-button` class | ||
| /// | ||
| /// It configures the `--_govuk-button-<COLOUR_NAME>` custom properties that apply colours to the button | ||
| /// with the appropriate `--_govuk-<VARIANT>-button-<COLOUR_NAME>` properties that define colours for a given variant. | ||
| /// | ||
| /// @access private | ||
| @mixin govuk-button-style($variant-name) { | ||
| @if not list.index($_available-variants, $variant-name) { | ||
| @error "Unknown button variant `#{$variant-name}` (available variants: #{$_available-variants})"; | ||
| } | ||
|
|
||
| --_govuk-button-background-colour: var(--_govuk-#{$variant-name}-button-background-colour); | ||
| --_govuk-button-shadow-colour: var(--_govuk-#{$variant-name}-button-shadow-colour); | ||
| --_govuk-button-text-colour: var(--_govuk-#{$variant-name}-button-text-colour); | ||
| --_govuk-button-hover-background-colour: var(--_govuk-#{$variant-name}-button-hover-background-colour); | ||
| } |
This file contains hidden or 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
41 changes: 41 additions & 0 deletions
41
packages/govuk-frontend/src/govuk/components/button/helpers.unit.test.mjs
This file contains hidden or 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 { compileSassString } from '@govuk-frontend/helpers/tests' | ||
| import { outdent } from 'outdent' | ||
|
|
||
| describe('button/_helpers', () => { | ||
| describe('@mixin govuk-button-style', () => { | ||
| it('Applies the appropriate variant custom properties to the button custom properties', async () => { | ||
| const sass = ` | ||
| @use "components/button/helpers" as *; | ||
|
|
||
| .app-component { | ||
| @include govuk-button-style(warning); | ||
| } | ||
| ` | ||
|
|
||
| const { css } = await compileSassString(sass) | ||
|
|
||
| expect(css).toEqual(outdent` | ||
| .app-component { | ||
| --_govuk-button-background-colour: var(--_govuk-warning-button-background-colour); | ||
| --_govuk-button-shadow-colour: var(--_govuk-warning-button-shadow-colour); | ||
| --_govuk-button-text-colour: var(--_govuk-warning-button-text-colour); | ||
| --_govuk-button-hover-background-colour: var(--_govuk-warning-button-hover-background-colour); | ||
| } | ||
| `) | ||
| }) | ||
|
|
||
| it('Throws an error if the variant does not exist', () => { | ||
| const sass = ` | ||
| @use "components/button/helpers" as *; | ||
|
|
||
| .app-component { | ||
| @include govuk-button-style(unknown-button-variant); | ||
| } | ||
| ` | ||
|
|
||
| expect(compileSassString(sass)).rejects.toThrow( | ||
| 'Unknown button variant `unknown-button-variant` (available variants: secondary, warning, inverse)' | ||
| ) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😎