@@ -10,6 +10,7 @@ import {
10
10
TEXT_STYLES ,
11
11
} from '../../../tasty' ;
12
12
import { accessibilityWarning } from '../../../utils/warnings' ;
13
+ import { Text } from '../../content/Text' ;
13
14
import { CubeActionProps } from '../Action/Action' ;
14
15
import { useAction } from '../use-action' ;
15
16
@@ -60,8 +61,16 @@ const STYLE_PROPS = [...CONTAINER_STYLES, ...TEXT_STYLES];
60
61
61
62
export const DEFAULT_BUTTON_STYLES = {
62
63
display : 'inline-grid' ,
63
- placeItems : 'center stretch' ,
64
- placeContent : 'center' ,
64
+ flow : 'column' ,
65
+ placeItems : 'center start' ,
66
+ placeContent : {
67
+ '' : 'center' ,
68
+ 'right-icon | suffix' : 'center stretch' ,
69
+ } ,
70
+ gridColumns : {
71
+ '' : 'initial' ,
72
+ 'left-icon | loading | prefix' : 'max-content' ,
73
+ } ,
65
74
position : 'relative' ,
66
75
margin : 0 ,
67
76
boxSizing : 'border-box' ,
@@ -73,7 +82,6 @@ export const DEFAULT_BUTTON_STYLES = {
73
82
'' : '.75x' ,
74
83
'[data-size="small"]' : '.5x' ,
75
84
} ,
76
- flow : 'column' ,
77
85
preset : {
78
86
'' : 't3m' ,
79
87
'[data-size="xsmall"]' : 't4' ,
@@ -85,19 +93,19 @@ export const DEFAULT_BUTTON_STYLES = {
85
93
outlineOffset : 1 ,
86
94
padding : {
87
95
'' : '.5x (1.5x - 1bw)' ,
88
- '[data-size="small"] | [data-size="xsmall"]' : '.5x (1x - 1bw)' ,
96
+ '[data-size="small"] | [data-size="xsmall"]' : '.5x (1.25x - 1bw)' ,
89
97
'[data-size="medium"]' : '.5x (1.5x - 1bw)' ,
90
- '[data-size="large"]' : '.5x (2x - 1bw)' ,
91
- '[data-size="xlarge"]' : '.5x (2.25x - 1bw)' ,
92
- 'single-icon-only | [data-type="link"]' : 0 ,
98
+ '[data-size="large"]' : '.5x (1.75x - 1bw)' ,
99
+ '[data-size="xlarge"]' : '.5x (2x - 1bw)' ,
100
+ 'single-icon | [data-type="link"]' : 0 ,
93
101
} ,
94
102
width : {
95
103
'' : 'initial' ,
96
- '[data-size="xsmall"] & single-icon-only ' : '@size-xs @size-xs' ,
97
- '[data-size="small"] & single-icon-only ' : '@size-sm @size-sm' ,
98
- '[data-size="medium"] & single-icon-only ' : '@size-md @size-md' ,
99
- '[data-size="large"] & single-icon-only ' : '@size-lg @size-lg' ,
100
- '[data-size="xlarge"] & single-icon-only ' : '@size-xl @size-xl' ,
104
+ '[data-size="xsmall"] & single-icon' : '@size-xs @size-xs' ,
105
+ '[data-size="small"] & single-icon' : '@size-sm @size-sm' ,
106
+ '[data-size="medium"] & single-icon' : '@size-md @size-md' ,
107
+ '[data-size="large"] & single-icon' : '@size-lg @size-lg' ,
108
+ '[data-size="xlarge"] & single-icon' : '@size-xl @size-xl' ,
101
109
'[data-type="link"]' : 'initial' ,
102
110
} ,
103
111
height : {
@@ -114,6 +122,20 @@ export const DEFAULT_BUTTON_STYLES = {
114
122
'' : true ,
115
123
'[data-type="link"] & !focused' : 0 ,
116
124
} ,
125
+
126
+ ButtonIcon : {
127
+ width : 'max-content' ,
128
+ } ,
129
+
130
+ '& [data-element="ButtonIcon"]:first-child:not(:last-child)' : {
131
+ marginLeft : '-.5x' ,
132
+ placeSelf : 'center start' ,
133
+ } ,
134
+
135
+ '& [data-element="ButtonIcon"]:last-child:not(:first-child)' : {
136
+ marginRight : '-.5x' ,
137
+ placeSelf : 'center end' ,
138
+ } ,
117
139
} as const ;
118
140
119
141
// ---------- DEFAULT THEME ----------
@@ -657,12 +679,16 @@ export const Button = forwardRef(function Button(
657
679
! children
658
680
) ;
659
681
682
+ const hasIcons = ! ! icon || ! ! rightIcon ;
683
+
660
684
const modifiers = useMemo (
661
685
( ) => ( {
662
686
loading : isLoading ,
663
687
selected : isSelected ,
664
- 'with-icons' : ! ! icon || ! ! rightIcon ,
665
- 'single-icon-only' : singleIcon ,
688
+ 'with-icons' : hasIcons ,
689
+ 'left-icon' : ! ! icon ,
690
+ 'right-icon' : ! ! rightIcon ,
691
+ 'single-icon' : singleIcon ,
666
692
...mods ,
667
693
} ) ,
668
694
[ mods , isDisabled , isLoading , isSelected , singleIcon ] ,
@@ -696,7 +722,12 @@ export const Button = forwardRef(function Button(
696
722
< LoadingIcon data-element = "ButtonIcon" />
697
723
)
698
724
) : null }
699
- { children }
725
+ { ( ( hasIcons && children ) || ( ! ! icon && ! ! rightIcon ) ) &&
726
+ typeof children === 'string' ? (
727
+ < Text ellipsis > { children } </ Text >
728
+ ) : (
729
+ children
730
+ ) }
700
731
{ rightIcon }
701
732
</ ButtonElement >
702
733
) ;
0 commit comments