@@ -10,6 +10,7 @@ import {
1010 TEXT_STYLES ,
1111} from '../../../tasty' ;
1212import { accessibilityWarning } from '../../../utils/warnings' ;
13+ import { Text } from '../../content/Text' ;
1314import { CubeActionProps } from '../Action/Action' ;
1415import { useAction } from '../use-action' ;
1516
@@ -60,8 +61,16 @@ const STYLE_PROPS = [...CONTAINER_STYLES, ...TEXT_STYLES];
6061
6162export const DEFAULT_BUTTON_STYLES = {
6263 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+ } ,
6574 position : 'relative' ,
6675 margin : 0 ,
6776 boxSizing : 'border-box' ,
@@ -73,7 +82,6 @@ export const DEFAULT_BUTTON_STYLES = {
7382 '' : '.75x' ,
7483 '[data-size="small"]' : '.5x' ,
7584 } ,
76- flow : 'column' ,
7785 preset : {
7886 '' : 't3m' ,
7987 '[data-size="xsmall"]' : 't4' ,
@@ -85,19 +93,19 @@ export const DEFAULT_BUTTON_STYLES = {
8593 outlineOffset : 1 ,
8694 padding : {
8795 '' : '.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)' ,
8997 '[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 ,
93101 } ,
94102 width : {
95103 '' : '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' ,
101109 '[data-type="link"]' : 'initial' ,
102110 } ,
103111 height : {
@@ -114,6 +122,20 @@ export const DEFAULT_BUTTON_STYLES = {
114122 '' : true ,
115123 '[data-type="link"] & !focused' : 0 ,
116124 } ,
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+ } ,
117139} as const ;
118140
119141// ---------- DEFAULT THEME ----------
@@ -657,12 +679,16 @@ export const Button = forwardRef(function Button(
657679 ! children
658680 ) ;
659681
682+ const hasIcons = ! ! icon || ! ! rightIcon ;
683+
660684 const modifiers = useMemo (
661685 ( ) => ( {
662686 loading : isLoading ,
663687 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 ,
666692 ...mods ,
667693 } ) ,
668694 [ mods , isDisabled , isLoading , isSelected , singleIcon ] ,
@@ -696,7 +722,12 @@ export const Button = forwardRef(function Button(
696722 < LoadingIcon data-element = "ButtonIcon" />
697723 )
698724 ) : null }
699- { children }
725+ { ( ( hasIcons && children ) || ( ! ! icon && ! ! rightIcon ) ) &&
726+ typeof children === 'string' ? (
727+ < Text ellipsis > { children } </ Text >
728+ ) : (
729+ children
730+ ) }
700731 { rightIcon }
701732 </ ButtonElement >
702733 ) ;
0 commit comments