diff --git a/.vscode/settings.json b/.vscode/settings.json index 700b9540..db29bd60 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,5 @@ { "cSpell.words": [ - "csspart", - "ondark" + "csspart" ] } diff --git a/apiExamples/disabledInverseAppearance.html b/apiExamples/disabledInverseAppearance.html new file mode 100644 index 00000000..0b7ec090 --- /dev/null +++ b/apiExamples/disabledInverseAppearance.html @@ -0,0 +1,4 @@ +Primary +Secondary +Tertiary +Ghost diff --git a/apiExamples/disabledOnDark.html b/apiExamples/disabledOnDark.html deleted file mode 100644 index 096a4c08..00000000 --- a/apiExamples/disabledOnDark.html +++ /dev/null @@ -1,4 +0,0 @@ -Primary -Secondary -Tertiary -Ghost diff --git a/apiExamples/inverseAppearance.html b/apiExamples/inverseAppearance.html new file mode 100644 index 00000000..8169b30f --- /dev/null +++ b/apiExamples/inverseAppearance.html @@ -0,0 +1,21 @@ + +Primary +Secondary +Tertiary +Ghost + +

+ + + + + + + +

+ + + + + + diff --git a/apiExamples/loadingInverseAppearance.html b/apiExamples/loadingInverseAppearance.html new file mode 100644 index 00000000..76e8e2be --- /dev/null +++ b/apiExamples/loadingInverseAppearance.html @@ -0,0 +1,4 @@ +Primary +Secondary +Tertiary +Ghost diff --git a/apiExamples/loadingOnDark.html b/apiExamples/loadingOnDark.html deleted file mode 100644 index 317ae83e..00000000 --- a/apiExamples/loadingOnDark.html +++ /dev/null @@ -1,4 +0,0 @@ -Primary -Secondary -Tertiary -Ghost diff --git a/apiExamples/onDark.html b/apiExamples/onDark.html deleted file mode 100644 index de29e7f1..00000000 --- a/apiExamples/onDark.html +++ /dev/null @@ -1,21 +0,0 @@ - -Primary -Secondary -Tertiary -Ghost - -

- - - - - - - -

- - - - - - diff --git a/apiExamples/shape.html b/apiExamples/shape.html index 7e10cb36..b4c0a4c9 100644 --- a/apiExamples/shape.html +++ b/apiExamples/shape.html @@ -1,8 +1,8 @@ Rounded Button Pill Button - + - + diff --git a/apiExamples/staticInverseAppearance.html b/apiExamples/staticInverseAppearance.html new file mode 100644 index 00000000..bc4445fa --- /dev/null +++ b/apiExamples/staticInverseAppearance.html @@ -0,0 +1,3 @@ +Static Primary Button +Static Secondary Button +Static Tertiary Button diff --git a/apiExamples/staticOnDark.html b/apiExamples/staticOnDark.html deleted file mode 100644 index f4fb5589..00000000 --- a/apiExamples/staticOnDark.html +++ /dev/null @@ -1,3 +0,0 @@ -Static Primary Button -Static Secondary Button -Static Tertiary Button diff --git a/demo/api.md b/demo/api.md new file mode 100644 index 00000000..24f6726a --- /dev/null +++ b/demo/api.md @@ -0,0 +1,706 @@ + + + +# auro-button + +## Properties + +| Property | Attribute | Type | Default | Description | +|---------------|---------------|--------------------------------------------------|-------------|--------------------------------------------------| +| [appearance](#appearance) | `appearance` | `'default', 'inverse'` | "'default'" | Defines whether the button will be on lighter or darker backgrounds. | +| [autofocus](#autofocus) | `autofocus` | `boolean` | false | This Boolean attribute lets you specify that the button should have input focus when the page loads, unless overridden by the user. | +| [disabled](#disabled) | `disabled` | `boolean` | false | If set to true, button will become disabled and not allow for interactions. | +| [fluid](#fluid) | `fluid` | `boolean` | false | Alters the shape of the button to be full width of its parent container. | +| [loading](#loading) | `loading` | `boolean` | false | If set to true button text will be replaced with `auro-loader` and become disabled. | +| [loadingText](#loadingText) | `loadingText` | `string` | | Sets custom loading text for the `aria-label` on a button in loading state. If not set, the default value of "Loading..." will be used. | +| [onDark](#onDark) | `ondark` | `boolean` | "{false}" | DEPRECATED - use `appearance` property | +| [shape](#shape) | `shape` | `'default', 'rounded', 'pill', 'circle', 'square'` | "rounded" | Defines the shape of the button. | +| [size](#size) | `size` | `'xs', 'sm', 'md', 'lg', 'xl'` | "md" | Defines the size of the button. | +| [static](#static) | `static` | `boolean` | false | If true, the button will be static and not respond to user interactions. | +| [tIndex](#tIndex) | `tIndex` | `string` | | Populates `tabindex` to define the focusable sequence in keyboard navigation. | +| [tabindex](#tabindex) | `tabindex` | `string` | | Populates `tabindex` to define the focusable sequence in keyboard navigation.
Must be used with "." to ensure the host element does not retain a reference to the `tabindex` attribute.
Example: ``. | +| [title](#title) | `title` | `string` | | Sets title attribute. The information is most often shown as a tooltip text when the mouse moves over the element. | +| [type](#type) | `type` | `'submit', 'reset', 'button'` | | The type of button. Matches HTML5 Button Spec. | +| [value](#value) | `value` | `string` | | Defines the value associated with the button which is submitted with the form data. | +| [variant](#variant) | `variant` | `'primary', 'secondary', 'tertiary', 'ghost', 'flat'` | "primary" | Sets the button variant. | + +## Methods + +| Method | Type | +|-------------------------------|------------| +| [resetLayoutClasses](#resetLayoutClasses) | `(): void` | +| [resetShapeClasses](#resetShapeClasses) | `(): void` | +| [updateComponentArchitecture](#updateComponentArchitecture) | `(): void` | + + +# API Examples + +## Basic + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + +
+ + + Primary + Secondary + Tertiary + Ghost +

+ + + + + +

+ + + + + + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +

+ + + + + +

+ + + + + +``` + +
+ +## Disabled + +This example demonstrates `auro-button` in it's `disabled` state. + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + + +## Static + +The `static` attribute creates a button with no interactivity. When applied, the button becomes non-clickable and serves purely as a visual element. This is useful for displaying button-styled elements that need to appear interactive but should not respond to user input, such as buttons within clickable cards or slides. + +
+ + + Static Primary Button + Static Secondary Button + Static Tertiary Button +

+ Static Fluid Button +

+ XS Static + SM Static + MD Static + LG Static + XL Static +

+ + + Static Pill with Icon + + + + + + + + +
+ + See code + + + +```html +Static Primary Button +Static Secondary Button +Static Tertiary Button +

+Static Fluid Button +

+XS Static +SM Static +MD Static +LG Static +XL Static +

+ + + Static Pill with Icon + + + + + + + +``` + +
+
+ + + Static Primary Button + Static Secondary Button + Static Tertiary Button + +
+ + See code + + + +```html +Static Primary Button +Static Secondary Button +Static Tertiary Button +``` + + + +## Icon Support + +Adding icons to the auro-button component is as easy as nesting any other HTML. The auro-icon component +has access to all the icons listed in the Auro Icons library +for quick and easy use. + +Be sure to use the customColor attribute on the `auro-icon` component to allow colors set in your parent element to pass through to the icon and `slot=icon` to properly place the `auro-icon` within the button. + +
+ + + + Activate WiFi + + + + Previous action + + + + Love this ... + + + +
+ + See code + + + +```html + + Activate WiFi + + + + Previous action + + + + Love this ... + + +``` + + + +## Shape +default - `rounded` + +#### Circle + +
+ + + + + + + + + + + + + + + + + + +
+ + See code + + + +```html + + + + + + + + + + + + + + + +``` + + + +#### Square + +
+ + + + + + + + + + + + + + + + + + +
+ + See code + + + +```html + + + + + + + + + + + + + + + +``` + + + +### Pill + +
+ + + Primary + Primary + Primary + Primary + Primary + +
+ + See code + + + +```html +Primary +Primary +Primary +Primary +Primary +``` + + + +#### Toggle Text + +The `rounded` attribute supports the ability to hide/show the text of the `auro-button`. This can be done by changing the value of the `iconOnly` attribute. In this example, the text is toggled via `mouseover` and `mouseout` events. The `focusin` and `focusout` events simulate toggling text for keyboard users. + +
+ + + + Text is now shown! + + + +
+ + See code + + + +```html + + Text is now shown! + + +``` + + + + +```js +export function toggledTextExample() { + const toggledTextElem = document.querySelector("#toggledTextElem"); + + // The mouseover and mouseout events are to simulate toggling text for mouse users + toggledTextElem.addEventListener("mouseover", () => { + toggledTextElem.shape = "pill"; + }); + + toggledTextElem.addEventListener("mouseout", () => { + toggledTextElem.shape = "circle"; + }); + + // The focusin and focusout events are to simulate toggling text for keyboard users + toggledTextElem.addEventListener("focusin", () => { + toggledTextElem.shape = "pill"; + }); + + toggledTextElem.addEventListener("focusout", () => { + toggledTextElem.shape = "circle"; + }); +} +``` + + + +#### Right Aligned + +This example shows a `rounded` `auro-button` that is right-aligned, demonstrating how the button starts from the right and grows/shrinks from right to left when using the `toggleText` attribute in conjuction with the `mouseover` and `mouseout` events. The `focusin` and `focusout` events simulate toggling text for keyboard users. + +
+ + +
+ + Text is now shown! + + +
+ +
+ + See code + + + +```html +
+ + Text is now shown! + + +
+``` + + + + +```js +export function roundedRightAlignExample() { + const rightAlignElem = document.querySelector("#rightAlignElem"); + + // The mouseover and mouseout events are to simulate toggling text for mouse users + rightAlignElem.addEventListener("mouseover", () => { + rightAlignElem.shape = "pill"; + }); + + rightAlignElem.addEventListener("mouseout", () => { + rightAlignElem.shape = "circle"; + }); + + // The focusin and focusout events are to simulate toggling text for keyboard users + rightAlignElem.addEventListener("focusin", () => { + rightAlignElem.shape = "pill"; + }); + + rightAlignElem.addEventListener("focusout", () => { + rightAlignElem.shape = "circle"; + }); +} +``` + +
+ +## Size +The size of the button can be set in t-shirt sizes from `xs` to `xl` + +
+ + + Extra Small + Small + Medium + Large + Extra Large + +
+ + See code + + + +```html +Extra Small +Small +Medium +Large +Extra Large +``` + + + +## Variant +Auro button can use several different variants, including `primary`, `secondary`, `tertiary`, `ghost`, and `flat`. + +The flat variant should only be used for interface elements that should only have a focus style such as close buttons on dialogs and clear buttons on form elements. + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + + +## Fluid + +In the following example see how the `fluid` attributes alters the shape of the button to be full width of its parent container. + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + + +## Loading State + +Use the `loading` attribute to alter the content to the shimmering dots to alert the user that the button/form is in an active state. The `loading` attribute will also place the element in a disabled state to keep the user from re-submitting an action. + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + + +### Loading text + +To provide a custom loading message for assistive technologies, use the `loadingText` attribute. If not provided, the default message will be "Loading...". + +
+ + + Primary + +
+ + See code + + + +```html +Primary +``` + + + +## ARIA Attributes + +Any ARIA attributes can be applied directly to the element and will be handled internally: + +`Auro Button` + +## Tab Index + +For `tabindex`, use `tIndex` instead to avoid duplicated focus interaction. + +## Theme Support + +The component may be restyled using the following code sample and changing the values of the following token(s). + + + + +```scss +@use "@aurodesignsystem/design-tokens/dist/themes/alaska/SCSSVariables--alaska" as v; + +:host { + --ds-auro-button-border-color: var(--ds-advanced-color-button-primary-border, #{v.$ds-advanced-color-button-primary-border}); + --ds-auro-button-border-inset-color: var(--ds-advanced-color-state-focused-inverse, #{v.$ds-advanced-color-state-focused-inverse}); + --ds-auro-button-container-color: var(--ds-advanced-color-button-primary-background, #{v.$ds-advanced-color-button-primary-background}); + --ds-auro-button-container-image: var(--ds-advanced-color-button-primary-background, #{v.$ds-advanced-color-button-primary-background}); + --ds-auro-button-loader-color: var(--ds-advanced-color-button-primary-text, #{v.$ds-advanced-color-button-primary-text}); + --ds-auro-button-text-color: var(--ds-advanced-color-button-primary-text, #{v.$ds-advanced-color-button-primary-text}); +} +``` + diff --git a/demo/button-sheet.html b/demo/button-sheet.html index 7eab5194..f9f9464b 100644 --- a/demo/button-sheet.html +++ b/demo/button-sheet.html @@ -71,31 +71,31 @@

XL

- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
@@ -137,31 +137,31 @@

LG

- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
@@ -203,31 +203,31 @@

MD

- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
@@ -269,31 +269,31 @@

SM

- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
@@ -335,31 +335,31 @@

XS

- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
- Button - Button - Button - Button + Button + Button + Button + Button
diff --git a/demo/icon-sheet.html b/demo/icon-sheet.html index a35f3ae1..a546cdd2 100644 --- a/demo/icon-sheet.html +++ b/demo/icon-sheet.html @@ -61,21 +61,21 @@

XL

- - - - - + + + + +
- - - - - + + + + +
@@ -107,21 +107,21 @@

LG

- - - - - + + + + +
- - - - - + + + + +
@@ -153,21 +153,21 @@

MD

- - - - - + + + + +
- - - - - + + + + +
@@ -199,21 +199,21 @@

SM

- - - - - + + + + +
- - - - - + + + + +
@@ -245,21 +245,21 @@

XS

- - - - - + + + + +
- - - - - + + + + +
diff --git a/demo/index.md b/demo/index.md new file mode 100644 index 00000000..8a1f1551 --- /dev/null +++ b/demo/index.md @@ -0,0 +1,415 @@ + + +# Button + + + +`` is a [HTML custom element](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements) for the purpose being a clickable element to trigger a specific action. + + +## Auro-Button use cases + + + +The auro-button element should be used in situations where users may: + +* submit a form +* begin a new task +* trigger a new UI element to appear to the page +* specify a new or next step in a process + + +## Buttons are not Hyperlinks + +In cases were the action of the button would not fit the criteria above, it is most likely a Hyperlink. In that situation it is recommended that the [auro-hyperlink](https://www.alaskaair.com/components/auro/hyperlink) element be used. + +## Default Examples + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + +
+ + + + + + + +

+ + + + + + +
+ + See code + + + +```html + + + + + +

+ + + + + +``` + +
+ +## Visual state on Dark Backgrounds + +These examples illustrate the core button types on dark backgrounds using the `appearance="inverse"` attribute . + +
+ + + Primary + Secondary + Tertiary + Ghost +

+ + + + + +

+ + + + + + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +

+ + + + + +

+ + + + + +``` + +
+ +## Disabled + +This example demonstrates `auro-button` in it's `disabled` state. + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + + +## Icon Support + +Adding icons to the auro-button component is as easy as nesting any other HTML. The [auro-icon component](https://www.alaskaair.com/components/auro/icon) has access to all the icons listed in the [Auro Icons library](https://www.alaskaair.com/icons/usage) for quick and easy use. + +Be sure to use the `customColor` attribute on the auro-icon component to allow colors set in your parent element to pass through to the icon. + +
+ + + + Activate WiFi + + + + Previous action + + + + Love this ... + + + +
+ + See code + + + +```html + + Activate WiFi + + + + Previous action + + + + Love this ... + + +``` + + + +## Size +The size of the button can be set in t-shirt sizes from `xs` to `xl` + +
+ + + Extra Small + Small + Medium + Large + Extra Large + +
+ + See code + + + +```html +Extra Small +Small +Medium +Large +Extra Large +``` + + + +## Shape +The button comes with several different shapes available, `pill`, `rounded`, `circle`, and `square`. + +
+ + + Rounded Button + Pill Button + + + + + + + +
+ + See code + + + +```html +Rounded Button +Pill Button + + + + + + +``` + + + +## Variant +Auro button can use several different variants, including `primary`, `secondary`, `tertiary`, `ghost`, and `flat`. + +The flat variant should only be used for interface elements that should only have a focus style such as close buttons on dialogs and clear buttons on form elements. + +
+ + + Primary + Secondary + Tertiary + Ghost + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +Ghost +``` + + + +## Pass a Function to Button + +These examples illustrate a common use case where a user will want to pass a function into a button to support a click event. See the code examples for how this is achieved. + +
+ + + Primary + Primary + Primary + +
+ + See code + + + +```html +Primary +Primary +Primary +``` + + + +## Do's and don'ts + +Don't combine `disabled` and `loading` attributes on any single instance of `auro-button`. An `auro-button` with `loading` *is* affectively a disabled instance. There is no need for both. + +
+ + + + Primary + + + Primary + + +
+ + See code + + + +```html + + Primary + + + Primary + +``` + + + +## Recommended Use and Version Control + +There are two important parts of every Auro component. The class and the custom element. The class is exported and then used as part of defining the Web Component. When importing this component as described in the install section, the class is imported and the `auro-button` custom element is defined automatically. + +To protect from versioning conflicts with other instances of the component being loaded, it is recommended to use our `AuroButton.register(name)` method and pass in a unique name. + +```js +import { AuroButton } from '@aurodesignsystem/auro-button/class'; + +AuroButton.register('custom-button'); +``` + +This will create a new custom element that you can use in your HTML that will function identically to the `` element. + +
+ + + Primary + Secondary + Tertiary + +
+ + See code + + + +```html +Primary +Secondary +Tertiary +``` + + diff --git a/docs/api.md b/docs/api.md index 037f65b3..f12496e5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -2,23 +2,24 @@ ## Properties -| Property | Attribute | Type | Default | Description | -|---------------|---------------|--------------------------------------------------|-----------|--------------------------------------------------| -| `autofocus` | `autofocus` | `boolean` | false | This Boolean attribute lets you specify that the button should have input focus when the page loads, unless overridden by the user. | -| `disabled` | `disabled` | `boolean` | false | If set to true, button will become disabled and not allow for interactions. | -| `fluid` | `fluid` | `boolean` | false | Alters the shape of the button to be full width of its parent container. | -| `loading` | `loading` | `boolean` | false | If set to true button text will be replaced with `auro-loader` and become disabled. | -| `loadingText` | `loadingText` | `string` | | Sets custom loading text for the `aria-label` on a button in loading state. If not set, the default value of "Loading..." will be used. | -| `onDark` | `ondark` | `boolean` | false | Indicates if the button is rendered in dark mode. | -| `shape` | `shape` | `'default', 'rounded', 'pill', 'circle', 'square'` | "rounded" | Defines the shape of the button. | -| `size` | `size` | `'xs', 'sm', 'md', 'lg', 'xl'` | "md" | Defines the size of the button. | -| `static` | `static` | `boolean` | false | If true, the button will be static and not respond to user interactions. | -| `tIndex` | `tIndex` | `string` | | Populates `tabindex` to define the focusable sequence in keyboard navigation. | -| `tabindex` | `tabindex` | `string` | | Populates `tabindex` to define the focusable sequence in keyboard navigation.
Must be used with "." to ensure the host element does not retain a reference to the `tabindex` attribute.
Example: ``. | -| `title` | `title` | `string` | | Sets title attribute. The information is most often shown as a tooltip text when the mouse moves over the element. | -| `type` | `type` | `'submit', 'reset', 'button'` | | The type of button. Matches HTML5 Button Spec. | -| `value` | `value` | `string` | | Defines the value associated with the button which is submitted with the form data. | -| `variant` | `variant` | `'primary', 'secondary', 'tertiary', 'ghost', 'flat'` | "primary" | Sets the button variant. | +| Property | Attribute | Type | Default | Description | +|---------------|---------------|--------------------------------------------------|-------------|--------------------------------------------------| +| `appearance` | `appearance` | `'default', 'inverse'` | "'default'" | Defines whether the button will be on lighter or darker backgrounds. | +| `autofocus` | `autofocus` | `boolean` | false | This Boolean attribute lets you specify that the button should have input focus when the page loads, unless overridden by the user. | +| `disabled` | `disabled` | `boolean` | false | If set to true, button will become disabled and not allow for interactions. | +| `fluid` | `fluid` | `boolean` | false | Alters the shape of the button to be full width of its parent container. | +| `loading` | `loading` | `boolean` | false | If set to true button text will be replaced with `auro-loader` and become disabled. | +| `loadingText` | `loadingText` | `string` | | Sets custom loading text for the `aria-label` on a button in loading state. If not set, the default value of "Loading..." will be used. | +| `onDark` | `ondark` | `boolean` | "{false}" | DEPRECATED - use `appearance` property | +| `shape` | `shape` | `'default', 'rounded', 'pill', 'circle', 'square'` | "rounded" | Defines the shape of the button. | +| `size` | `size` | `'xs', 'sm', 'md', 'lg', 'xl'` | "md" | Defines the size of the button. | +| `static` | `static` | `boolean` | false | If true, the button will be static and not respond to user interactions. | +| `tIndex` | `tIndex` | `string` | | Populates `tabindex` to define the focusable sequence in keyboard navigation. | +| `tabindex` | `tabindex` | `string` | | Populates `tabindex` to define the focusable sequence in keyboard navigation.
Must be used with "." to ensure the host element does not retain a reference to the `tabindex` attribute.
Example: ``. | +| `title` | `title` | `string` | | Sets title attribute. The information is most often shown as a tooltip text when the mouse moves over the element. | +| `type` | `type` | `'submit', 'reset', 'button'` | | The type of button. Matches HTML5 Button Spec. | +| `value` | `value` | `string` | | Defines the value associated with the button which is submitted with the form data. | +| `variant` | `variant` | `'primary', 'secondary', 'tertiary', 'ghost', 'flat'` | "primary" | Sets the button variant. | ## Methods diff --git a/docs/partials/api.md b/docs/partials/api.md index 85851f91..3ae49bc2 100644 --- a/docs/partials/api.md +++ b/docs/partials/api.md @@ -19,14 +19,14 @@
- +
See code - + @@ -49,14 +49,14 @@ This example demonstrates `auro-button` in it's `disabled` state.
- +
See code - + @@ -79,14 +79,14 @@ The `static` attribute creates a button with no interactivity. When applied, the
- +
See code - + @@ -270,14 +270,14 @@ Use the `loading` attribute to alter the content to the shimmering dots to alert
- +
See code - + diff --git a/docs/partials/index.md b/docs/partials/index.md index 231efc7f..f353b251 100644 --- a/docs/partials/index.md +++ b/docs/partials/index.md @@ -47,19 +47,19 @@ In cases were the action of the button would not fit the criteria above, it is m -## On Dark +## Visual state on Dark Backgrounds -These examples illustrate the core button types and a `disabled` state on dark backgrounds using the `onDark` attribute. +These examples illustrate the core button types on dark backgrounds using the `appearance="inverse"` attribute .
- +
See code - + @@ -82,14 +82,14 @@ This example demonstrates `auro-button` in it's `disabled` state.
- +
See code - + diff --git a/src/auro-button.js b/src/auro-button.js index 1d72dcff..a27d6aa7 100644 --- a/src/auro-button.js +++ b/src/auro-button.js @@ -43,7 +43,8 @@ const ICON_ONLY_SHAPES = ["circle", "square"]; * @property {'xs', 'sm', 'md', 'lg', 'xl'} size - Defines the size of the button. * @property {'primary', 'secondary', 'tertiary', 'ghost', 'flat'} variant - Sets the button variant. * @property {'submit', 'reset', 'button'} type - The type of button. Matches HTML5 Button Spec. - * @property {boolean} onDark - Indicates if the button is rendered in dark mode. + * @property {boolean} onDark - DEPRECATED - use `appearance` property + * @property {'default', 'inverse'} appearance - Defines whether the button will be on lighter or darker backgrounds. */ export class AuroButton extends AuroElement { /** @@ -63,7 +64,6 @@ export class AuroButton extends AuroElement { this.static = false; this.size = "md"; this.shape = "rounded"; - this.onDark = false; this.fluid = false; this.loadingText = this.loadingText || "Loading..."; this.variant = "primary"; diff --git a/src/layoutElement/auroElement.js b/src/layoutElement/auroElement.js index 6b183d72..0c3294c4 100644 --- a/src/layoutElement/auroElement.js +++ b/src/layoutElement/auroElement.js @@ -46,7 +46,17 @@ export class AuroElement extends LitElement { }, /** - * This Boolean attribute lets you specify that the element should be rendered in dark mode. + * Defines whether the button will be on lighter or darker backgrounds. + * @property {'default', 'inverse'} + * @default 'default' + */ + appearance: { + type: String, + reflect: true + }, + + /** + * DEPRECATED - use `appearance` attribute. * @default {false} */ onDark: { @@ -69,6 +79,13 @@ export class AuroElement extends LitElement { }; } + constructor() { + super(); + + this.onDark = false; + this.appearance = 'default'; + } + resetShapeClasses() { if (this.shape && this.size) { if (this.wrapper) { diff --git a/src/styles/color.scss b/src/styles/color.scss index 7bc226fd..cdaa1581 100644 --- a/src/styles/color.scss +++ b/src/styles/color.scss @@ -162,7 +162,8 @@ // ONDARK DEFAULT / PRIMARY -:host([onDark]) { +:host([onDark]), +:host([appearance="inverse"]) { --ds-auro-button-border-color: var(--ds-advanced-color-button-primary-border-inverse, #{v.$ds-advanced-color-button-primary-border-inverse}); --ds-auro-button-border-inset-color: var(--ds-advanced-color-state-focused-inverse, #{v.$ds-advanced-color-state-focused-inverse}); --ds-auro-button-container-color: var(--ds-advanced-color-button-primary-background-inverse, #{v.$ds-advanced-color-button-primary-background-inverse}); @@ -171,17 +172,20 @@ --ds-auro-button-text-color: var(--ds-advanced-color-button-primary-text-inverse, #{v.$ds-advanced-color-button-primary-text-inverse}); } -:host([ondark]:not([disabled]):is([data-hover], [data-active])) { +:host([ondark]:not([disabled]):is([data-hover], [data-active])), +:host([appearance="inverse"]:not([disabled]):is([data-hover], [data-active])) { --ds-auro-button-border-color: var(--ds-advanced-color-button-primary-border-inverse-hover, #{v.$ds-advanced-color-button-primary-border-inverse-hover}); --ds-auro-button-container-color: var(--ds-advanced-color-button-primary-background-inverse-hover, #{v.$ds-advanced-color-button-primary-background-inverse-hover}); --ds-auro-button-container-image: var(--ds-advanced-color-button-primary-background-inverse-hover, #{v.$ds-advanced-color-button-primary-background-inverse-hover}); } -:host([ondark]:focus-within) { +:host([ondark]:focus-within), +:host([appearance="inverse"]:focus-within) { --ds-auro-button-border-inset-color: var(--ds-advanced-color-state-focused, #{v.$ds-advanced-color-state-focused}); } -:host([ondark][disabled]) { +:host([ondark][disabled]), +:host([appearance="inverse"][disabled]) { --ds-auro-button-border-color: var(--ds-advanced-color-button-primary-border-inverse-disabled, #{v.$ds-advanced-color-button-primary-border-inverse-disabled}); --ds-auro-button-container-color: var(--ds-advanced-color-button-primary-background-inverse-disabled, #{v.$ds-advanced-color-button-primary-background-inverse-disabled}); --ds-auro-button-container-image: var(--ds-advanced-color-button-primary-background-inverse-disabled, #{v.$ds-advanced-color-button-primary-background-inverse-disabled}); @@ -189,7 +193,8 @@ } // ONDARK SECONDARY -:host([ondark][variant='secondary']) { +:host([ondark][variant='secondary']), +:host([appearance="inverse"][variant='secondary']) { --ds-auro-button-container-color: transparent; --ds-auro-button-container-image: transparent; --ds-auro-button-border-color: var(--ds-advanced-color-button-secondary-border-inverse, #{v.$ds-advanced-color-button-secondary-border-inverse}); @@ -197,23 +202,27 @@ --ds-auro-button-loader-color: var(--ds-advanced-color-button-secondary-text-inverse, #{v.$ds-advanced-color-button-secondary-text-inverse}); } -:host([ondark][variant='secondary']:not([disabled]):is([data-hover], [data-active])) { +:host([ondark][variant='secondary']:not([disabled]):is([data-hover], [data-active])), +:host([appearance="inverse"][variant='secondary']:not([disabled]):is([data-hover], [data-active])) { --ds-auro-button-text-color: var(--ds-advanced-color-button-secondary-text-inverse, #{v.$ds-advanced-color-button-secondary-text-inverse}); --ds-auro-button-container-color: var(--ds-advanced-color-button-secondary-background-inverse-hover, #{v.$ds-advanced-color-button-secondary-background-inverse-hover}); --ds-auro-button-container-image: var(--ds-advanced-color-button-secondary-background-inverse-hover, #{v.$ds-advanced-color-button-secondary-background-inverse-hover}); } -:host([ondark][variant='secondary']:focus-within) { +:host([ondark][variant='secondary']:focus-within), +:host([appearance="inverse"][variant='secondary']:focus-within) { --ds-auro-button-border-inset-color: var(--ds-advanced-color-state-focused-inverse, #{v.$ds-advanced-color-state-focused-inverse}); } -:host([ondark][variant='secondary'][disabled]) { +:host([ondark][variant='secondary'][disabled]), +:host([appearance="inverse"][variant='secondary'][disabled]) { --ds-auro-button-text-color: var(--ds-basic-color-texticon-inverse-disabled, #{v.$ds-basic-color-texticon-inverse-disabled}); --ds-auro-button-border-color: var(--ds-advanced-color-button-secondary-border-inverse-disabled, #{v.$ds-advanced-color-button-secondary-border-inverse-disabled}); } // ONDARK TERTIARY -:host([ondark][variant='tertiary']) { +:host([ondark][variant='tertiary']), +:host([appearance="inverse"][variant='tertiary']) { --ds-auro-button-container-color: var(--ds-advanced-color-button-tertiary-background-inverse, #{v.$ds-advanced-color-button-tertiary-background-inverse}); --ds-auro-button-container-image: var(--ds-advanced-color-button-tertiary-background-inverse, #{v.$ds-advanced-color-button-tertiary-background-inverse}); --ds-auro-button-border-color: transparent; @@ -221,22 +230,26 @@ --ds-auro-button-loader-color: var(--ds-advanced-color-button-tertiary-text-inverse, #{v.$ds-advanced-color-button-tertiary-text-inverse}); } -:host([ondark][variant='tertiary']:not([disabled]):is([data-hover], [data-active])) { +:host([ondark][variant='tertiary']:not([disabled]):is([data-hover], [data-active])), +:host([appearance="inverse"][variant='tertiary']:not([disabled]):is([data-hover], [data-active])) { --ds-auro-button-container-color: var(--ds-advanced-color-button-tertiary-background-inverse-hover, #{v.$ds-advanced-color-button-tertiary-background-inverse-hover}); --ds-auro-button-container-image: var(--ds-advanced-color-button-tertiary-background-inverse-hover, #{v.$ds-advanced-color-button-tertiary-background-inverse-hover}); } -:host([ondark][variant='tertiary']:focus-within) { +:host([ondark][variant='tertiary']:focus-within), +:host([appearance="inverse"][variant='tertiary']:focus-within) { --ds-auro-button-border-color: var(--ds-advanced-color-state-focused-inverse, #{v.$ds-advanced-color-state-focused-inverse}); --ds-auro-button-border-inset-color: var(--ds-advanced-color-state-focused-inverse, #{v.$ds-advanced-color-state-focused-inverse}); } -:host([ondark][variant='tertiary'][disabled]) { +:host([ondark][variant='tertiary'][disabled]), +:host([appearance="inverse"][variant='tertiary'][disabled]) { --ds-auro-button-text-color: var(--ds-basic-color-texticon-inverse-disabled, #{v.$ds-basic-color-texticon-inverse-disabled}); } // ONDARK GHOST -:host([ondark][variant='ghost']) { +:host([ondark][variant='ghost']), +:host([appearance="inverse"][variant='ghost']) { --ds-auro-button-container-color: transparent; --ds-auro-button-container-image: transparent; --ds-auro-button-border-color: transparent; @@ -244,23 +257,27 @@ --ds-auro-button-loader-color: var(--ds-advanced-color-button-ghost-text-inverse, #{v.$ds-advanced-color-button-ghost-text-inverse}); } -:host([ondark][variant='ghost']:not([disabled]):is([data-hover], [data-active])) { +:host([ondark][variant='ghost']:not([disabled]):is([data-hover], [data-active])), +:host([appearance="inverse"][variant='ghost']:not([disabled]):is([data-hover], [data-active])) { --ds-auro-button-container-color: var(--ds-advanced-color-button-ghost-background-inverse-hover, #{v.$ds-advanced-color-button-ghost-background-inverse-hover}); --ds-auro-button-container-image: var(--ds-advanced-color-button-ghost-background-inverse-hover, #{v.$ds-advanced-color-button-ghost-background-inverse-hover}); --ds-auro-button-border-color: transparent; } -:host([ondark][variant='ghost']:focus-within) { +:host([ondark][variant='ghost']:focus-within), +:host([appearance="inverse"][variant='ghost']:focus-within) { border-color: transparent; --ds-auro-button-border-inset-color: var(--ds-advanced-color-state-focused-inverse, #{v.$ds-advanced-color-state-focused-inverse}); } -:host([ondark][variant='ghost'][disabled]) { +:host([ondark][variant='ghost'][disabled]), +:host([appearance="inverse"][variant='ghost'][disabled]) { --ds-auro-button-text-color: var(--ds-basic-color-texticon-inverse-disabled, #{v.$ds-basic-color-texticon-inverse-disabled}); } // ONDARK FLAT -:host([ondark][variant='flat']) { +:host([ondark][variant='flat']), +:host([appearance="inverse"][variant='flat']) { .auro-button { color: var(--ds-advanced-color-button-flat-text-inverse, #{v.$ds-advanced-color-button-flat-text-inverse}); background-color: transparent; @@ -284,7 +301,8 @@ } } -:host([ondark][variant='flat']:focus-within) { +:host([ondark][variant='flat']:focus-within), +:host([appearance="inverse"][variant='flat']:focus-within) { --ds-auro-button-border-color: var(--ds-advanced-color-state-focused-inverse, #{v.$ds-advanced-color-state-focused-inverse}); --ds-auro-button-border-inset-color: var(--ds-advanced-color-state-focused-inverse, #{v.$ds-advanced-color-state-focused-inverse}); } diff --git a/test/auro-button.test.js b/test/auro-button.test.js index 0ba11b78..c0490132 100644 --- a/test/auro-button.test.js +++ b/test/auro-button.test.js @@ -56,9 +56,9 @@ describe("auro-button", () => { expect(button.getAttribute("disabled")).to.equal(""); }); - it("tests setting ondark", async () => { + it("tests setting inverse appearance", async () => { const el = await fixture(html` - Click Me! + Click Me! `); const root = el.shadowRoot; @@ -66,7 +66,7 @@ describe("auro-button", () => { const classList = button.getAttribute("class").split(" "); expect(classList.includes("auro-button")).to.be.true; - expect(el.hasAttribute("ondark")).to.be.true; + expect(el.getAttribute("appearance")).to.equal("inverse"); }); it("tests setting secondary", async () => { @@ -82,9 +82,9 @@ describe("auro-button", () => { expect(el.getAttribute("variant")).to.equal("secondary"); }); - it("tests setting secondary ondark", async () => { + it("tests setting secondary inverse appearance", async () => { const el = await fixture(html` - Click Me! + Click Me! `); const root = el.shadowRoot; @@ -92,7 +92,7 @@ describe("auro-button", () => { const classList = button.getAttribute("class").split(" "); expect(classList.includes("auro-button")).to.be.true; - expect(el.hasAttribute("ondark")).to.be.true; + expect(el.getAttribute("appearance")).to.equal("inverse"); expect(el.getAttribute("variant")).to.equal("secondary"); }); @@ -109,9 +109,9 @@ describe("auro-button", () => { expect(el.getAttribute("variant")).to.equal("tertiary"); }); - it("tests setting tertiary ondark", async () => { + it("tests setting tertiary inverse appearance", async () => { const el = await fixture(html` - Click Me! + Click Me! `); const root = el.shadowRoot; @@ -119,7 +119,7 @@ describe("auro-button", () => { const classList = button.getAttribute("class").split(" "); expect(classList.includes("auro-button")).to.be.true; - expect(el.hasAttribute("ondark")).to.be.true; + expect(el.getAttribute("appearance")).to.equal("inverse"); expect(el.getAttribute("variant")).to.equal("tertiary"); });