Skip to content

Commit

Permalink
feat: LoadingButton
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl-J-M committed Mar 25, 2024
1 parent 3c56beb commit d2c597b
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 1 deletion.
71 changes: 71 additions & 0 deletions components/content/LoadingButton/LoadingButton.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@keyframes pulse {
0% {
background-position: 200% 0;
}

100% {
background-position: -200% 0;
}
}

diamond-loading-button {
--_size: 1rem;
--_padding-block: var(--diamond-button-padding-block);
--_padding-inline: var(--diamond-button-padding-inline);
--_line-height: var(--diamond-button-line-height);

button,
a,
input:not([type='file']),
input[type='file']::file-selector-button {
align-items: center;
animation: pulse 1.5s infinite linear;
appearance: none;
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
background-size: 200% 100%;
border: transparent;
color: transparent;
display: inline-block;
justify-content: center;
letter-spacing: inherit;
line-height: var(--_line-height);
min-height: var(--diamond-spacing-thumb);
min-width: var(--diamond-spacing-thumb);
padding-block: var(--_padding-block);
padding-inline: var(--_padding-inline);
touch-action: none;
}

svg {
block-size: var(--diamond-icon-size);
flex-shrink: 0;
inline-size: var(--diamond-icon-size);
}

&[width='full-width'] {
display: block;

button,
a,
input {
width: 100%;
}
}

@media (width < 480px) {
&[width='full-width-mobile'] {
display: block;

button,
a,
input {
width: 100%;
}
}
}

&[width='square'] {
--_line-height: 1;
--_padding-inline: var(--diamond-button-padding-block);
}
}
31 changes: 31 additions & 0 deletions components/content/LoadingButton/LoadingButton.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { StoryObj } from '@storybook/web-components';
import { html } from 'lit';

import './LoadingButton';

export default {
component: 'diamond-loading-button',
parameters: {
docs: {
description: {
component: 'Loading version of the Button component.',
},
},
},
argTypes: {
width: {
control: {
type: 'select',
},
options: ['full-width', 'full-width-mobile', 'square'],
},
},
};

export const Button: StoryObj = {
render: (args) => html`
<diamond-loading-button size="${args.size}" width="${args.width}">
<button type="button">Loading...</button>
</diamond-loading-button>
`,
};
20 changes: 20 additions & 0 deletions components/content/LoadingButton/LoadingButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { JSXCustomElement } from '../../../types/jsx-custom-element';

export interface LoadingButtonAttributes {
variant?: 'primary' | 'secondary' | 'text';
width?: 'full-width' | 'full-width-mobile' | 'square';
}

declare global {
interface HTMLElementTagNameMap {
'diamond-loading-button': LoadingButtonAttributes;
}
}

declare module 'react' {
namespace JSX {
interface IntrinsicElements {
'diamond-loading-button': LoadingButtonAttributes & JSXCustomElement;
}
}
}
1 change: 0 additions & 1 deletion components/control/Button/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { JSXCustomElement } from '../../../types/jsx-custom-element';

export interface ButtonAttributes {
size?: 'sm' | 'md' | 'lg';
variant?: 'primary' | 'secondary' | 'text';
width?: 'full-width' | 'full-width-mobile' | 'square';
}

Expand Down

0 comments on commit d2c597b

Please sign in to comment.