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

feature: adding motion to button component #933

Merged
merged 8 commits into from
Jan 20, 2025
4 changes: 4 additions & 0 deletions packages/core/src/components/button/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ button {
justify-content: center;
}

&.animation-fade {
transition: background-color var(--tds-motion-duration-fast-02) var(--tds-motion-easing-scania);
}

@each $type in $types {
&.#{$type} {
@each $prop in $props {
Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/components/button/button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ export default {
defaultValue: { summary: false },
},
},
animation: {
name: 'Animation',
description: 'Sets the animation for the Button.',
control: {
type: 'radio',
},
options: ['none', 'fade'],
table: {
defaultValue: { summary: 'none' },
},
},
},
args: {
modeVariant: 'Inherit from parent',
Expand All @@ -128,6 +139,7 @@ export default {
onlyIcon: false,
icon: 'none',
disabled: false,
animation: 'none',
},
};

Expand All @@ -141,6 +153,7 @@ const WebComponentTemplate = ({
onlyIcon,
icon,
disabled,
animation,
}) => {
const variantLookUp = {
Primary: 'primary',
Expand Down Expand Up @@ -186,6 +199,7 @@ const WebComponentTemplate = ({
? `mode-variant="${modeVariantLookup[modeVariant]}"`
: ''
}
animation="${animation}"
>
${
onlyIcon || (icon && icon !== 'none')
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export class TdsButton {
/** Set the mode variant of the Button. */
@Prop() modeVariant: 'primary' | 'secondary' = null;

/** Determines if and how the button should animate. */
@Prop() animation: 'none' | 'fade' = 'none';

@State() onlyIcon: boolean = false;

render() {
Expand Down Expand Up @@ -64,6 +67,7 @@ export class TdsButton {
'fullbleed': this.fullbleed,
'icon': hasIconSlot,
'only-icon': this.onlyIcon,
[`animation-${this.animation}`]: this.animation !== 'none',
}}
>
{this.text}
Expand Down
19 changes: 10 additions & 9 deletions packages/core/src/components/button/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ------------- | -------------- | ----------------------------------------- | ------------------------------------------------- | ----------- |
| `disabled` | `disabled` | Control for disabled state of a component | `boolean` | `false` |
| `fullbleed` | `fullbleed` | When enabled, the Button takes 100% width | `boolean` | `false` |
| `modeVariant` | `mode-variant` | Set the mode variant of the Button. | `"primary" \| "secondary"` | `null` |
| `size` | `size` | Size of a Button | `"lg" \| "md" \| "sm" \| "xs"` | `'lg'` |
| `text` | `text` | Text displayed inside the Button | `string` | `undefined` |
| `type` | `type` | Button's type | `"button" \| "reset" \| "submit"` | `'button'` |
| `variant` | `variant` | Variation of Button's design | `"danger" \| "ghost" \| "primary" \| "secondary"` | `'primary'` |
| Property | Attribute | Description | Type | Default |
| ------------- | -------------- | ------------------------------------------------ | ------------------------------------------------- | ----------- |
| `animation` | `animation` | Determines if and how the button should animate. | `"fade" \| "none"` | `'none'` |
| `disabled` | `disabled` | Control for disabled state of a component | `boolean` | `false` |
| `fullbleed` | `fullbleed` | When enabled, the Button takes 100% width | `boolean` | `false` |
| `modeVariant` | `mode-variant` | Set the mode variant of the Button. | `"primary" \| "secondary"` | `null` |
| `size` | `size` | Size of a Button | `"lg" \| "md" \| "sm" \| "xs"` | `'lg'` |
| `text` | `text` | Text displayed inside the Button | `string` | `undefined` |
| `type` | `type` | Button's type | `"button" \| "reset" \| "submit"` | `'button'` |
| `variant` | `variant` | Variation of Button's design | `"danger" \| "ghost" \| "primary" \| "secondary"` | `'primary'` |


## Slots
Expand Down