Skip to content

Commit

Permalink
feat(core): button file update
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSzidat committed Jan 3, 2022
1 parent d39bbbe commit 76665dc
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 15 deletions.
6 changes: 2 additions & 4 deletions packages/core/Button/default.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<template>
<button-base class="design-default" v-bind="$attrs" v-on="$listeners">
<slot name="default" />
</button-base>
<button-base class="design-default" v-bind="$attrs" v-on="$listeners" />
</template>

<script>
Expand All @@ -20,7 +18,7 @@ export default {
.design-default {
position: relative;
&.style-loading {
&.loading {
pointer-events: none;
& >>> * {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/Button/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
v-on="$listeners"
>
<slot name="icon" />
<slot>
<slot name="default">
<span v-if="label" v-html="label" />
</slot>
</button>
Expand All @@ -19,7 +19,7 @@ export default {
props: {
label: {
type: String,
default: 'Button Label'
default: null
},
disabled: {
type: Boolean,
Expand All @@ -33,8 +33,8 @@ export default {
computed: {
classes () {
return {
'style-disabled': this.disabled,
'style-loading': this.loading
disabled: this.disabled,
loading: this.loading
};
}
}
Expand Down
11 changes: 6 additions & 5 deletions packages/core/Button/mutation/Icon/index.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<base-button class="icon-button" :class="classes" v-bind="$attrs" v-on="$listeners">
<template #icon>
<base-icon :size="iconSize" />
</template>
<template #default>
<slot name="icon" :iconName="iconName">
<base-icon :size="iconSize" />
</slot>
<slot name="default" :label="label">
<span v-if="label" v-html="label" />
</slot>
Expand Down Expand Up @@ -60,12 +60,13 @@ export default {
.icon-button {
position: relative;
display: flex;
align-items: center;
&.style-reversed-order {
flex-direction: row-reverse;
}
&.style-loading {
&.loading {
pointer-events: none;
& > * {
Expand All @@ -89,7 +90,7 @@ export default {
}
}
&.style-disabled {
&[disabled] {
& .icon {
opacity: 0.5;
}
Expand Down
152 changes: 152 additions & 0 deletions packages/core/Button/mutation/file/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<template>
<base-button class="file-button" :class="classes" v-bind="$attrs" v-on="$listeners">
<template #icon>
<base-icon :size="iconSize">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 374.116 374.116" style="enable-background: new 0 0 374.116 374.116;" xml:space="preserve"><path d="M344.058 207.506c-16.568 0-30 13.432-30 30v76.609h-254v-76.609c0-16.568-13.432-30-30-30-16.568 0-30 13.432-30 30v106.609c0 16.568 13.432 30 30 30h314c16.568 0 30-13.432 30-30V237.506c0-16.568-13.432-30-30-30 z" /><path d="m123.57 135.915 33.488-33.488v111.775c0 16.568 13.432 30 30 30 16.568 0 30-13.432 30-30V102.426l33.488 33.488c5.857 5.858 13.535 8.787 21.213 8.787 7.678 0 15.355-2.929 21.213-8.787 11.716-11.716 11.716-30.71 0-42.426l-84.701-84.7c-11.715-11.717-30.711-11.717-42.426 0L81.144 93.489c-11.716 11.716-11.716 30.71 0 42.426 11.715 11.716 30.711 11.716 42.426 0 z" />
</svg>
</base-icon>
</template>
<template #default>
<span v-if="label" v-html="label" />
<input
type="file"
:accept="accept"
@change="onChangeInput"
>
</template>
</base-button>
</template>

<script>
import BaseButton from '../../index';
import BaseIcon from '../../../Icon';
export default {
components: {
BaseButton,
BaseIcon
},
props: {
label: {
type: String,
default: null
},
iconName: {
type: String,
default: 'iconName'
},
iconSize: {
type: String,
default: 'xs'
},
reversedOrder: {
type: Boolean,
default: false
},
accept: {
type: String,
default: null
},
multiple: {
type: Boolean,
default: false
}
},
data () {
return {
};
},
computed: {
classes () {
return {
'style-reversed-order': this.reversedOrder
};
}
},
methods: {
onChangeInput (e) {
console.log('onChangeInput', e.target.files);
this.$emit('change', e.target.files);
}
}
};
</script>

<style lang="postcss" scoped>
.file-button {
position: relative;
display: flex;
align-items: center;
&.style-reversed-order {
flex-direction: row-reverse;
}
&.loading {
pointer-events: none;
& > * {
opacity: 0;
}
&::after {
position: absolute;
top: 50%;
left: 50%;
box-sizing: border-box;
width: 1em;
height: 1em;
content: "";
border: 0.2em solid rgb(0 0 0 / 100%);
border-top-color: rgb(0 0 0 / 30%);
border-radius: 50%;
transform: translate(-50%, -50%);
transform-origin: 50% 50%;
animation: spin 0.5s infinite linear;
}
}
&[disabled] {
& .icon {
opacity: 0.5;
}
}
& .icon {
margin: 0 0.3em;
&.xs {
width: 1em;
}
&.sm {
width: 2em;
}
&.md {
width: 3em;
}
}
& input[type="file"] {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
}
}
@keyframes spin {
0% {
transform: translate(-50%, -50%) rotate(0deg);
}
100% {
transform: translate(-50%, -50%) rotate(360deg);
}
}
</style>
12 changes: 10 additions & 2 deletions packages/sample/pages/button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<fieldset>
<legend>Mutation icon button, reversedOrder</legend>
<form>
<button-icon icon-name="icn" icon-size="xs" label="IconButton" :reversed-order="true" />
<button-icon icon-name="icn" icon-size="md" label="IconButton" :reversed-order="true" />
</form>
</fieldset>
<fieldset>
Expand All @@ -49,6 +49,12 @@
<button-icon icon-name="icn" icon-size="xs" :loading="true" label="IconButton loading" />
</form>
</fieldset>
<fieldset>
<legend>Mutation file</legend>
<form>
<button-file icon-name="icn" icon-size="xs" label="Upload" />
</form>
</fieldset>
</div>
</template>

Expand All @@ -57,12 +63,14 @@
import BaseButton from '@foundation/core/Button';
import DefaultButton from '@foundation/core/Button/default';
import ButtonIcon from '@foundation/core/Button/mutation/Icon';
import ButtonFile from '@foundation/core/Button/mutation/File';
export default {
components: {
BaseButton,
DefaultButton,
ButtonIcon
ButtonIcon,
ButtonFile
},
data () {
return {
Expand Down

0 comments on commit 76665dc

Please sign in to comment.