This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
feat(Button): add size
prop
#1716
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8b98a27
use p & v pattern
layershifter dd3fbb1
add size prop
layershifter 914d9fb
update styles, variables, add example
layershifter b38a76c
update example description
layershifter 3f49dc0
add changelog entry
layershifter 2085e6d
apply review comments
layershifter 952319f
Merge branch 'master' of https://github.com/stardust-ui/react into fe…
layershifter c6a7cc4
handle minWidth properly
layershifter 38d3f99
Merge branch 'master' into feat/button-size
layershifter 11e5a67
Merge branch 'master' into feat/button-size
layershifter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
docs/src/examples/components/Button/Variations/ButtonExampleSize.shorthand.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Button, Divider, Flex } from '@stardust-ui/react' | ||
import * as React from 'react' | ||
|
||
const ButtonExampleSizeShorthand: React.FC = () => ( | ||
<> | ||
<Flex gap="gap.smaller"> | ||
<Button size="smallest" content="Smallest" /> | ||
<Button size="smaller" content="Smaller" /> | ||
<Button size="small" content="Small" /> | ||
</Flex> | ||
<Divider /> | ||
|
||
<Button content="Medium (default)" /> | ||
<Divider /> | ||
|
||
<Flex gap="gap.smaller"> | ||
<Button size="large" content="Large" /> | ||
<Button size="larger" content="Larger" /> | ||
<Button size="largest" content="Largest" /> | ||
</Flex> | ||
</> | ||
) | ||
|
||
export default ButtonExampleSizeShorthand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 77 additions & 113 deletions
190
packages/react/src/themes/teams/components/Button/buttonStyles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,215 +1,179 @@ | ||
import { pxToRem } from '../../../../lib' | ||
import { ComponentSlotStylesInput, ICSSInJSStyle } from '../../../types' | ||
import { ButtonProps, ButtonState } from '../../../../components/Button/Button' | ||
import { ButtonVariables } from './buttonVariables' | ||
import getBorderFocusStyles from '../../getBorderFocusStyles' | ||
|
||
const buttonStyles: ComponentSlotStylesInput<ButtonProps & ButtonState, ButtonVariables> = { | ||
root: ({ props, variables, theme: { siteVariables } }): ICSSInJSStyle => { | ||
const { circular, disabled, fluid, primary, text, iconOnly, isFromKeyboard } = props | ||
root: ({ props: p, variables: v, theme: { siteVariables } }): ICSSInJSStyle => { | ||
const { borderWidth } = siteVariables | ||
|
||
const { | ||
height, | ||
minWidth, | ||
maxWidth, | ||
borderRadius, | ||
circularBorderRadius, | ||
paddingLeftRightValue, | ||
|
||
color, | ||
colorHover, | ||
colorFocus, | ||
colorDisabled, | ||
backgroundColor, | ||
backgroundColorActive, | ||
backgroundColorHover, | ||
backgroundColorFocus, | ||
backgroundColorDisabled, | ||
borderColor, | ||
borderColorHover, | ||
borderColorDisabled, | ||
|
||
primaryColor, | ||
primaryColorHover, | ||
primaryColorFocus, | ||
primaryBackgroundColor, | ||
primaryBackgroundColorActive, | ||
primaryBackgroundColorHover, | ||
primaryBackgroundColorFocus, | ||
primaryBorderColor, | ||
|
||
circularColor, | ||
circularColorActive, | ||
circularBackgroundColor, | ||
circularBackgroundColorActive, | ||
circularBackgroundColorHover, | ||
circularBackgroundColorFocus, | ||
circularBorderColor, | ||
circularBorderColorHover, | ||
circularBorderColorFocus, | ||
|
||
textColor, | ||
textColorHover, | ||
textPrimaryColor, | ||
textPrimaryColorHover, | ||
boxShadow, | ||
} = variables | ||
|
||
const { ':focus': borderFocusStyles } = getBorderFocusStyles({ | ||
siteVariables, | ||
isFromKeyboard, | ||
...(circular && { | ||
borderRadius: circularBorderRadius, | ||
focusOuterBorderColor: circularBorderColorFocus, | ||
isFromKeyboard: p.isFromKeyboard, | ||
...(p.circular && { | ||
borderRadius: v.circularBorderRadius, | ||
focusOuterBorderColor: v.circularBorderColorFocus, | ||
}), | ||
}) | ||
|
||
return { | ||
height, | ||
minWidth, | ||
maxWidth, | ||
color, | ||
backgroundColor, | ||
borderRadius, | ||
height: v.height, | ||
minWidth: v.minWidth, | ||
maxWidth: v.maxWidth, | ||
color: v.color, | ||
backgroundColor: v.backgroundColor, | ||
borderRadius: v.borderRadius, | ||
display: 'inline-flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
position: 'relative', | ||
padding: `0 ${pxToRem(paddingLeftRightValue)}`, | ||
padding: v.padding, | ||
verticalAlign: 'middle', | ||
cursor: 'pointer', | ||
|
||
// rectangular button defaults | ||
...(!text && { | ||
...(!p.text && { | ||
outline: 0, | ||
borderWidth, | ||
borderStyle: 'solid', | ||
borderColor, | ||
boxShadow, | ||
borderColor: v.borderColor, | ||
boxShadow: v.boxShadow, | ||
|
||
':hover': { | ||
color: colorHover, | ||
backgroundColor: backgroundColorHover, | ||
borderColor: borderColorHover, | ||
color: v.colorHover, | ||
backgroundColor: v.backgroundColorHover, | ||
borderColor: v.borderColorHover, | ||
}, | ||
|
||
':focus': { | ||
boxShadow: 'none', | ||
...(isFromKeyboard | ||
...(p.isFromKeyboard | ||
? { | ||
color: colorFocus, | ||
backgroundColor: backgroundColorFocus, | ||
color: v.colorFocus, | ||
backgroundColor: v.backgroundColorFocus, | ||
...borderFocusStyles, | ||
} | ||
: { ':active': { backgroundColor: backgroundColorActive } }), | ||
: { ':active': { backgroundColor: v.backgroundColorActive } }), | ||
}, | ||
}), | ||
|
||
// circular button defaults | ||
...(circular && | ||
!text && { | ||
minWidth: height, | ||
...(p.circular && | ||
!p.text && { | ||
minWidth: v.height, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, shouldn't this be updated depending on the size? It seems like a special case.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
padding: 0, | ||
color: circularColor, | ||
backgroundColor: circularBackgroundColor, | ||
borderColor: circularBorderColor, | ||
borderRadius: circularBorderRadius, | ||
color: v.circularColor, | ||
backgroundColor: v.circularBackgroundColor, | ||
borderColor: v.circularBorderColor, | ||
borderRadius: v.circularBorderRadius, | ||
|
||
':hover': { | ||
color: circularColorActive, | ||
backgroundColor: circularBackgroundColorHover, | ||
borderColor: circularBorderColorHover, | ||
color: v.circularColorActive, | ||
backgroundColor: v.circularBackgroundColorHover, | ||
borderColor: v.circularBorderColorHover, | ||
}, | ||
|
||
':focus': { | ||
boxShadow: 'none', | ||
...(isFromKeyboard | ||
...(p.isFromKeyboard | ||
? { | ||
color: circularColorActive, | ||
backgroundColor: circularBackgroundColorFocus, | ||
color: v.circularColorActive, | ||
backgroundColor: v.circularBackgroundColorFocus, | ||
...borderFocusStyles, | ||
} | ||
: { ':active': { backgroundColor: circularBackgroundColorActive } }), | ||
: { ':active': { backgroundColor: v.circularBackgroundColorActive } }), | ||
}, | ||
}), | ||
|
||
// text button defaults | ||
...(text && { | ||
color: textColor, | ||
...(p.text && { | ||
color: v.textColor, | ||
backgroundColor: 'transparent', | ||
borderColor: 'transparent', | ||
':hover': { | ||
color: textColorHover, | ||
color: v.textColorHover, | ||
}, | ||
...(primary && { | ||
color: textPrimaryColor, | ||
...(p.primary && { | ||
color: v.textPrimaryColor, | ||
':hover': { | ||
color: textPrimaryColorHover, | ||
color: v.textPrimaryColorHover, | ||
}, | ||
}), | ||
|
||
':focus': { | ||
boxShadow: 'none', | ||
outline: 'none', | ||
...(isFromKeyboard && borderFocusStyles), | ||
...(p.isFromKeyboard && borderFocusStyles), | ||
}, | ||
}), | ||
|
||
// Overrides for "primary" buttons | ||
...(primary && | ||
!text && { | ||
color: primaryColor, | ||
backgroundColor: primaryBackgroundColor, | ||
borderColor: primaryBorderColor, | ||
...(p.primary && | ||
!p.text && { | ||
color: v.primaryColor, | ||
backgroundColor: v.primaryBackgroundColor, | ||
borderColor: v.primaryBorderColor, | ||
|
||
':hover': { | ||
color: primaryColorHover, | ||
backgroundColor: primaryBackgroundColorHover, | ||
color: v.primaryColorHover, | ||
backgroundColor: v.primaryBackgroundColorHover, | ||
}, | ||
|
||
':focus': { | ||
boxShadow: 'none', | ||
...(isFromKeyboard | ||
...(p.isFromKeyboard | ||
? { | ||
color: primaryColorFocus, | ||
backgroundColor: primaryBackgroundColorFocus, | ||
color: v.primaryColorFocus, | ||
backgroundColor: v.primaryBackgroundColorFocus, | ||
...borderFocusStyles, | ||
} | ||
: { ':active': { backgroundColor: primaryBackgroundColorActive } }), | ||
: { ':active': { backgroundColor: v.primaryBackgroundColorActive } }), | ||
}, | ||
}), | ||
|
||
// Overrides for "disabled" buttons | ||
...(disabled && { | ||
...(p.disabled && { | ||
cursor: 'default', | ||
color: colorDisabled, | ||
backgroundColor: backgroundColorDisabled, | ||
borderColor: borderColorDisabled, | ||
color: v.colorDisabled, | ||
backgroundColor: v.backgroundColorDisabled, | ||
borderColor: v.borderColorDisabled, | ||
boxShadow: 'none', | ||
':hover': { | ||
backgroundColor: backgroundColorDisabled, | ||
backgroundColor: v.backgroundColorDisabled, | ||
}, | ||
}), | ||
|
||
...(fluid && { | ||
...(p.fluid && { | ||
width: '100%', | ||
maxWidth: '100%', | ||
}), | ||
|
||
...(iconOnly && { | ||
minWidth: height, | ||
...(p.size === 'small' && { | ||
padding: v.sizeSmallPadding, | ||
height: v.sizeSmallHeight, | ||
minWidth: v.sizeSmallMinWidth, | ||
}), | ||
|
||
...(p.iconOnly && { | ||
minWidth: v.height, | ||
padding: 0, | ||
}), | ||
} | ||
}, | ||
|
||
// modifies the text of the button | ||
content: ({ variables }): ICSSInJSStyle => ({ | ||
content: ({ props: p, variables: v }): ICSSInJSStyle => ({ | ||
overflow: 'hidden', | ||
textOverflow: 'ellipsis', | ||
whiteSpace: 'nowrap', | ||
fontWeight: variables.contentFontWeight, | ||
fontSize: v.contentFontSize, | ||
fontWeight: v.contentFontWeight, | ||
lineHeight: v.contentLineHeight, | ||
|
||
...(p.size === 'small' && { | ||
fontSize: v.sizeSmallContentFontSize, | ||
lineHeight: v.sizeSmallContentLineHeight, | ||
}), | ||
}), | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to consolidate the description of the size in the components' examples. We have different for Avatar, Text, Button.. :\