@@ -22,7 +22,9 @@ It can be used with one or multiple actions.
22
22
<NcCheckboxRadioSwitch v-model="style" value="icon" name="style" type="radio">Icon only</NcCheckboxRadioSwitch>
23
23
<NcCheckboxRadioSwitch v-model="style" value="icontext" name="style" type="radio">Icon and text</NcCheckboxRadioSwitch>
24
24
<NcCheckboxRadioSwitch v-model="disabled" type="checkbox">Disabled</NcCheckboxRadioSwitch>
25
- <!--<NcCheckboxRadioSwitch v-model="readonly" type="checkbox">Read-only</NcCheckboxRadioSwitch>-->
25
+ <NcCheckboxRadioSwitch v-model="size" value="small" name="size" type="radio">Small</NcCheckboxRadioSwitch>
26
+ <NcCheckboxRadioSwitch v-model="size" value="normal" name="size" type="radio">Normal (default)</NcCheckboxRadioSwitch>
27
+ <NcCheckboxRadioSwitch v-model="size" value="large" name="size" type="radio">Large</NcCheckboxRadioSwitch>
26
28
</div>
27
29
28
30
<h5>Standard buttons</h5>
@@ -34,7 +36,7 @@ It can be used with one or multiple actions.
34
36
<NcButton
35
37
aria-label="Example text"
36
38
:disabled="disabled"
37
- :readonly="readonly "
39
+ :size="size "
38
40
type="tertiary-no-background">
39
41
<template v-if="style.indexOf('icon') !== -1" #icon>
40
42
<Video
@@ -45,7 +47,7 @@ It can be used with one or multiple actions.
45
47
<NcButton
46
48
aria-label="Example text"
47
49
:disabled="disabled"
48
- :readonly="readonly "
50
+ :size="size "
49
51
type="tertiary">
50
52
<template v-if="style.indexOf('icon') !== -1" #icon>
51
53
<Video
@@ -56,7 +58,7 @@ It can be used with one or multiple actions.
56
58
<NcButton
57
59
aria-label="Example text"
58
60
:disabled="disabled"
59
- :readonly="readonly ">
61
+ :size="size ">
60
62
<template v-if="style.indexOf('icon') !== -1" #icon>
61
63
<Video
62
64
:size="20" />
@@ -66,7 +68,7 @@ It can be used with one or multiple actions.
66
68
<NcButton
67
69
aria-label="Example text"
68
70
:disabled="disabled"
69
- :readonly="readonly "
71
+ :size="size "
70
72
type="primary">
71
73
<template v-if="style.indexOf('icon') !== -1" #icon>
72
74
<Video
@@ -80,7 +82,7 @@ It can be used with one or multiple actions.
80
82
<h5>Wide button</h5>
81
83
<NcButton
82
84
:disabled="disabled"
83
- :readonly="readonly "
85
+ :size="size "
84
86
:wide="true"
85
87
text="Example text">
86
88
<template #icon>
@@ -99,7 +101,7 @@ It can be used with one or multiple actions.
99
101
<p> - </p>
100
102
<NcButton
101
103
:disabled="disabled"
102
- :readonly="readonly "
104
+ :size="size "
103
105
type="success">
104
106
<template #icon>
105
107
<Video
@@ -109,7 +111,7 @@ It can be used with one or multiple actions.
109
111
</NcButton>
110
112
<NcButton
111
113
:disabled="disabled"
112
- :readonly="readonly "
114
+ :size="size "
113
115
type="warning">
114
116
<template #icon>
115
117
<Video
@@ -119,7 +121,7 @@ It can be used with one or multiple actions.
119
121
</NcButton>
120
122
<NcButton
121
123
:disabled="disabled"
122
- :readonly="readonly "
124
+ :size="size "
123
125
type="error">
124
126
<template #icon>
125
127
<Video
@@ -143,7 +145,7 @@ export default {
143
145
return {
144
146
toggled: false,
145
147
disabled: false,
146
- readonly: false ,
148
+ size: 'normal' ,
147
149
style: 'icontext',
148
150
}
149
151
}
@@ -157,6 +159,7 @@ export default {
157
159
158
160
.grid {
159
161
display: grid;
162
+ gap: 12px;
160
163
grid-template-columns: 1fr 1fr 1fr 1fr;
161
164
grid-template-rows: repeat(auto-fill, auto);
162
165
position: relative;
@@ -459,6 +462,18 @@ export default defineComponent({
459
462
default: false,
460
463
},
461
464
465
+ /**
466
+ * Specify the button size
467
+ * Accepted values: `'small'`, `'normal'` (default), `'large'`
468
+ */
469
+ size: {
470
+ type: String,
471
+ default: 'normal',
472
+ validator(value: string) {
473
+ return ['small', 'normal', 'large'].includes(value)
474
+ },
475
+ },
476
+
462
477
/**
463
478
* Specifies the button type
464
479
* If left empty, the default button style will be applied.
@@ -468,8 +483,8 @@ export default defineComponent({
468
483
*/
469
484
type: {
470
485
type: String as PropType<typeof BUTTON_TYPES[number]>,
471
- validator(value) {
472
- return typeof value === 'string' && (BUTTON_TYPES as readonly string[]).indexOf (value) !== -1
486
+ validator(value: string ) {
487
+ return (BUTTON_TYPES as readonly string[]).includes (value)
473
488
},
474
489
default: 'secondary',
475
490
},
@@ -622,6 +637,7 @@ export default defineComponent({
622
637
{
623
638
class: [
624
639
'button-vue',
640
+ `button-vue--size-${this.size}`,
625
641
{
626
642
'button-vue--icon-only': hasIcon && !hasText,
627
643
'button-vue--text-only': hasText && !hasIcon,
@@ -692,17 +708,31 @@ export default defineComponent({
692
708
</script>
693
709
694
710
<style lang="scss" scoped>
695
-
696
711
.button-vue {
712
+ // Setup different button sizes
713
+ --button-size: var(--default-clickable-area);
714
+ --button-radius: var(--border-radius-element, calc(var(--button-size) / 2));
715
+ --button-padding: clamp(var(--default-grid-baseline), var(--button-radius), calc(var(--default-grid-baseline) * 4));
716
+
717
+ &--size-small {
718
+ --button-size: var(--clickable-area-small, 24px);
719
+ --button-radius: var(--border-radius); // make the border radius even smaller for small buttons
720
+ }
721
+
722
+ &--size-large {
723
+ --button-size: var(--clickable-area-large, 48px);
724
+ }
725
+
726
+ // General styles
697
727
position: relative;
698
728
width: fit-content;
699
729
overflow: hidden;
700
730
border: 0;
701
731
padding: 0;
702
732
font-size: var(--default-font-size);
703
733
font-weight: bold;
704
- min-height: var(--default-clickable-area );
705
- min-width: var(--default-clickable-area );
734
+ min-height: var(--button-size );
735
+ min-width: var(--button-size );
706
736
display: flex;
707
737
align-items: center;
708
738
justify-content: center;
@@ -713,7 +743,7 @@ export default defineComponent({
713
743
span {
714
744
cursor: pointer;
715
745
}
716
- border-radius: var(--border -radius-element, calc(var(--default-clickable-area) / 2) );
746
+ border-radius: var(--button -radius);
717
747
transition-property: color, border-color, background-color;
718
748
transition-duration: 0.1s;
719
749
transition-timing-function: linear;
@@ -764,18 +794,29 @@ export default defineComponent({
764
794
}
765
795
766
796
&--reverse#{&}--icon-and-text {
767
- padding-inline: calc( var(--default-grid-baseline) * 4 ) var(--default-grid-baseline);
797
+ padding-inline: var(--button-padding ) var(--default-grid-baseline);
768
798
}
769
799
770
800
&__icon {
771
- height: var(--default-clickable-area );
772
- width: var(--default-clickable-area );
773
- min-height: var(--default-clickable-area );
774
- min-width: var(--default-clickable-area );
801
+ height: var(--button-size );
802
+ width: var(--button-size );
803
+ min-height: var(--button-size );
804
+ min-width: var(--button-size );
775
805
display: flex;
776
806
justify-content: center;
777
807
align-items: center;
778
808
}
809
+ // For small buttons we need to adjust the icon size
810
+ &--size-small &__icon {
811
+ :deep(> *) {
812
+ max-height: 16px;
813
+ max-width: 16px;
814
+ }
815
+ :deep(svg) {
816
+ height: 16px;
817
+ width: 16px;
818
+ }
819
+ }
779
820
780
821
&__text {
781
822
font-weight: bold;
@@ -789,12 +830,12 @@ export default defineComponent({
789
830
// Icon-only button
790
831
&--icon-only {
791
832
line-height: 1;
792
- width: var(--default-clickable-area ) !important;
833
+ width: var(--button-size ) !important;
793
834
}
794
835
795
836
// Text-only button
796
837
&--text-only {
797
- padding: 0 12px ;
838
+ padding: 0 var(--button-padding) ;
798
839
& .button-vue__text {
799
840
margin-left: 4px;
800
841
margin-right: 4px;
@@ -803,8 +844,11 @@ export default defineComponent({
803
844
804
845
// Icon and text button
805
846
&--icon-and-text {
847
+ // icon and text means the icon adds "visual" padding thus we need to adjust the text padding
848
+ --button-padding: min(calc(var(--default-grid-baseline) + var(--button-radius)), calc(var(--default-grid-baseline) * 4));
849
+ // Adjust padding as the icon already got some padding we need to reduce the padding on the icon side and only add larger padding to the text side
806
850
padding-block: 0;
807
- padding-inline: var(--default-grid-baseline) calc( var(--default-grid-baseline) * 4 );
851
+ padding-inline: var(--default-grid-baseline) var(--button-padding );
808
852
}
809
853
810
854
// Wide button spans the whole width of the container
0 commit comments