Skip to content

Commit

Permalink
feat(Button): Added truncated feature to Buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
johan-fx committed Sep 24, 2024
1 parent b906b08 commit c713e1e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 7 deletions.
3 changes: 3 additions & 0 deletions packages/components/src/form/Button/Button.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const BUTTON_DEFAULT_PROPS = {
textAlign: BUTTON_TEXT_ALIGN[0],
useAria: true,
isSelected: false,
truncated: false,
};

export const BUTTON_PROP_TYPES = {
Expand Down Expand Up @@ -49,4 +50,6 @@ export const BUTTON_PROP_TYPES = {
ariaLabel: PropTypes.string,
/** Controls if Button is selected */
isSelected: PropTypes.bool,
/** Controls if Button is truncated */
truncated: PropTypes.bool,
};
2 changes: 2 additions & 0 deletions packages/components/src/form/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const Button = forwardRef(
compact, // UNUSED
gradient, // UNUSED
radius, // UNUSED
truncated,
...props
},
ref,
Expand Down Expand Up @@ -62,6 +63,7 @@ const Button = forwardRef(
isSelected,
onlyIcon: !children,
iconSize: props.iconSize,
truncated,
},
{ name: 'Button' },
);
Expand Down
13 changes: 13 additions & 0 deletions packages/components/src/form/Button/Button.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export const ButtonStyles = createStyles(
isSelected,
onlyIcon,
iconSize,
truncated,
},
) => {
const currentVariant = getVariant(variant, theme, color);
Expand Down Expand Up @@ -242,6 +243,17 @@ export const ButtonStyles = createStyles(
};
}

let truncateProps = {};
if (truncated) {
truncateProps = {
display: 'inline-block',
overflow: 'hidden',
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
width: '100%',
};
}

return {
root: {
border: `${buttonTheme.border.width} solid`,
Expand Down Expand Up @@ -285,6 +297,7 @@ export const ButtonStyles = createStyles(
label: {
...buttonTheme.content.typo,
fontSize: variant === 'linkInline' ? 'inherit' : null,
...truncateProps,
},
};
},
Expand Down
41 changes: 34 additions & 7 deletions packages/components/src/tokens.compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ export default {
"y": 0,
"blur": 4,
"spread": 0,
"color": "#ffffff26",
"color": "#ffffff",
"type": "dropShadow"
},
"type": "boxShadow"
Expand Down Expand Up @@ -1625,8 +1625,17 @@ export default {
"type": "color"
},
"hover--reverse-transparent": {
"value": "#ffffff26",
"type": "color"
"value": "#ffffff",
"type": "color",
"$extensions": {
"studio.tokens": {
"modify": {
"type": "alpha",
"value": "0.15",
"space": "lch"
}
}
}
},
"down": {
"value": "#F1FFBD",
Expand Down Expand Up @@ -5286,12 +5295,30 @@ export default {
"color": {
"primary": {
"default": {
"value": "#4d535866",
"type": "color"
"value": "#4D5358",
"type": "color",
"$extensions": {
"studio.tokens": {
"modify": {
"type": "alpha",
"value": "0.4",
"space": "lch"
}
}
}
},
"hover": {
"value": "#4d5358b3",
"type": "color"
"value": "#4D5358",
"type": "color",
"$extensions": {
"studio.tokens": {
"modify": {
"type": "alpha",
"value": "0.7",
"space": "lch"
}
}
}
},
"down": {
"value": "#4D5358",
Expand Down

0 comments on commit c713e1e

Please sign in to comment.