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

feat: add button component #2 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .stories/Button/Button.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script>
import { Button } from 'svelte-admin'

function click() {
alert('hello from button')
}
const colors = ['primary', 'success', 'danger', 'warning']
</script>

<Button text="Click!" on:click={click} />
{#each colors as color}
<Button {color}>{color}</Button>
{/each}
5 changes: 5 additions & 0 deletions .stories/Button/Disabled.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import { Button } from 'svelte-admin'
</script>

<Button disabled color="primary">Disabled</Button>
34 changes: 34 additions & 0 deletions .stories/Button/Icon.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script>
import { Button } from 'svelte-admin'

const colors = ['primary', 'success', 'danger', 'warning']
</script>

{#each colors as color}
<Button {color}>
<svg
slot="icon"
fill="white"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="50"
height="50"
viewBox="0 0 16 17">
<defs>
<path
id="prefix__a"
d="M14.707
6.707l-.045.043-.027.023c-.116.095-.254.165-.406.2l-.112.02c-.037.005-.074.007-.111.007H9c-.552
0-1-.448-1-1s.448-1 1-1h3.155C11.073 3.735 9.603 3 8 3 4.686
3 2 5.686 2 9s2.686 6 6 6 6-2.686 6-6c0-.552.448-1 1-1s1
.448 1 1c0 4.418-3.582 8-8 8s-8-3.582-8-8 3.582-8 8-8c1.892
0 3.632.734 5 1.999V1c0-.552.448-1 1-1s1 .448 1 1v4.994c0
.033-.001.067-.004.1l-.009.066c-.003.02-.007.042-.012.062-.012.055-.03.109-.05.16l-.022.048c-.027.056-.058.109-.094.158l-.02.027-.02.024c-.015.019-.031.037-.048.054l-.014.014z" />
</defs>
<g>
<use fill="white" fill-rule="nonzero" xlink:href="#prefix__a" />
</g>
</svg>
{color}
</Button>
{/each}
10 changes: 10 additions & 0 deletions .stories/Button/Link.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
import { Button } from 'svelte-admin'
const colors = ['primary', 'success', 'danger', 'warning']
</script>

{#each colors as color}
<Button href="/" target="__blank" rel="noreferrer noopener" {color}>
{color} link
</Button>
{/each}
8 changes: 4 additions & 4 deletions .stories/Button/Outline.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script>
import { Button } from 'svelte-admin'

function click() {
alert('hello from button')
}
const colors = ['primary', 'success', 'danger', 'warning']
</script>

<Button outline text="click" on:click={click} />
{#each colors as color}
<Button outline {color}>{color}</Button>
{/each}
34 changes: 34 additions & 0 deletions .stories/Button/RTL.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script>
import { Button } from 'svelte-admin'

const colors = ['primary', 'success', 'danger', 'warning']
</script>

{#each colors as color}
<Button size="md" dir="rtl" {color}>
<svg
slot="icon"
fill="white"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="50"
height="50"
viewBox="0 0 16 17">
<defs>
<path
id="prefix__a"
d="M14.707
6.707l-.045.043-.027.023c-.116.095-.254.165-.406.2l-.112.02c-.037.005-.074.007-.111.007H9c-.552
0-1-.448-1-1s.448-1 1-1h3.155C11.073 3.735 9.603 3 8 3 4.686
3 2 5.686 2 9s2.686 6 6 6 6-2.686 6-6c0-.552.448-1 1-1s1
.448 1 1c0 4.418-3.582 8-8 8s-8-3.582-8-8 3.582-8 8-8c1.892
0 3.632.734 5 1.999V1c0-.552.448-1 1-1s1 .448 1 1v4.994c0
.033-.001.067-.004.1l-.009.066c-.003.02-.007.042-.012.062-.012.055-.03.109-.05.16l-.022.048c-.027.056-.058.109-.094.158l-.02.027-.02.024c-.015.019-.031.037-.048.054l-.014.014z" />
</defs>
<g>
<use fill="white" fill-rule="nonzero" xlink:href="#prefix__a" />
</g>
</svg>
{color}
</Button>
{/each}
39 changes: 39 additions & 0 deletions .stories/Button/Size.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script>
import { Button } from 'svelte-admin'

const colors = ['primary', 'success', 'danger', 'warning']
</script>

{#each colors as color}
<Button size="md" {color}>{color}</Button>
{/each}
<br />
<br />
{#each colors as color}
<Button size="md" {color} icon>
<svg
slot="icon"
fill="white"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="50"
height="50"
viewBox="0 0 16 17">
<defs>
<path
id="prefix__a"
d="M14.707
6.707l-.045.043-.027.023c-.116.095-.254.165-.406.2l-.112.02c-.037.005-.074.007-.111.007H9c-.552
0-1-.448-1-1s.448-1 1-1h3.155C11.073 3.735 9.603 3 8 3 4.686
3 2 5.686 2 9s2.686 6 6 6 6-2.686 6-6c0-.552.448-1 1-1s1
.448 1 1c0 4.418-3.582 8-8 8s-8-3.582-8-8 3.582-8 8-8c1.892
0 3.632.734 5 1.999V1c0-.552.448-1 1-1s1 .448 1 1v4.994c0
.033-.001.067-.004.1l-.009.066c-.003.02-.007.042-.012.062-.012.055-.03.109-.05.16l-.022.048c-.027.056-.058.109-.094.158l-.02.027-.02.024c-.015.019-.031.037-.048.054l-.014.014z" />
</defs>
<g>
<use fill="white" fill-rule="nonzero" xlink:href="#prefix__a" />
</g>
</svg>
{color}
</Button>
{/each}
28 changes: 24 additions & 4 deletions .stories/Button/index.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
<script>
import Button from './Button.svelte'
import Outline from './Outline.svelte'
import Icon from './Icon.svelte'
import Size from './Size.svelte'
import Disabled from './Disabled.svelte'
import Link from './Link.svelte'
import RTL from './RTL.svelte'
</script>

<!-- We can add mutiple variations of components as a single component in storybook -->

<h3>Colored button!</h3>
<h1>Buttons</h1>
<br />
<h2>Colors</h2>
<Button />

<h3>Simple button!</h3>
<h2>Outline</h2>
<Outline />

<h2>Icon</h2>
<Icon />

<h2>Size</h2>
<Size />

<h2>Disabled</h2>
<Disabled />

<h2>Link</h2>
<Link />

<h2>RTL</h2>
<RTL />
2 changes: 1 addition & 1 deletion .stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ const story = Component => () => ({
Component,
})

storiesOf('Components', module).add('Button Component', story(Button))
storiesOf('Components', module).add('Button', story(Button))
144 changes: 144 additions & 0 deletions Button/Button.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
@import '../styles/variables.scss';
@import '../styles/mixins.scss';

.btn {
--bg-color: $primary;
@include btn();

&-primary {
background-color: $primary;
border: 1px solid $primary;
&:not([disabled]):hover {
background-color: $primary-hover;
border-color: $primary-hover-border-color;
color: $white;
}
&:not([disabled]):active,
&:not([disabled]):focus {
background-color: $primary-hover;
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.5);
color: $white;
}
}
&-success {
background-color: $success;
border: 1px solid $success;
&:not([disabled]):hover {
background-color: $success-hover;
border-color: $success-hover-border-color;
color: $white;
}
&:not([disabled]):active,
&:not([disabled]):focus {
background-color: $success-hover;
box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.5);
color: $white;
}
}
&-danger {
background-color: $danger;
border: 1px solid $danger;
&:not([disabled]):hover {
background-color: $danger-hover;
border-color: $danger-hover-border-color;
color: $white;
}
&:not([disabled]):active,
&:not([disabled]):focus {
background-color: $danger-hover;
box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.5);
color: $white;
}
}
&-warning {
background-color: $warning;
border: 1px solid $warning;
&:not([disabled]):hover {
background-color: $warning-hover;
border-color: $warning-hover-border-color;
color: $white;
}
&:not([disabled]):active,
&:not([disabled]):focus {
background-color: $warning-hover;
box-shadow: 0 0 0 0.2rem rgba(255, 193, 7, 0.5);
color: $white;
}
}
&-outline-primary {
background: none;
border: 1px solid $primary;
color: $primary;
}
&-outline-danger {
background: none;
border: 1px solid $danger;
color: $danger;
}
&-outline-success {
background: none;
border: 1px solid $success;
color: $success;
}
&-outline-warning {
background: none;
border: 1px solid $warning;
color: $warning;
}
&-block {
display: block;
width: 100%;
}
&-size-md {
min-width: 340px;
}
&-size-sm {
min-width: 164px;
}

&-size-lg {
min-width: 640px;
}
.icon {
width: 24px;
height: 24px;
border-radius: 50%;
background-color: var(--bg-color);
margin-inline-end: 4px;
@include center-horizontally();
}
&.btn-size-md.ltr .icon,
&.btn-size-lg.ltr .icon {
position: absolute;
left: 5%;
top: 50%;
transform: translateY(-50%);
}
&.btn-size-md.rtl .icon,
&.btn-size-lg.rtl .icon {
position: absolute;
right: 5%;
top: 50%;
transform: translateY(-50%);
}
}
a {
text-decoration: none;
}
button:disabled,
a.disabled {
background-color: rgba(0, 0, 0, 0.12);
color: rgba(0, 0, 0, 0.26);
pointer-events: none;
cursor: default;
border: none;
&:hover {
background-color: none;
color: none;
box-shadow: none;
}
}
span.icon :global(*) {
max-width: 16px;
max-height: 16px;
}
Loading