Skip to content

Commit 3125e2d

Browse files
feat: exported icon button styling to reduce code duplication
1 parent e38c86a commit 3125e2d

File tree

4 files changed

+8
-43
lines changed

4 files changed

+8
-43
lines changed

src/components/IconButton/IconButton.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const disabled = {
2626
opacity: 0.4,
2727
}
2828

29-
export const StyledIconButton = styled(DEFAULT_TAG, {
29+
export const IconButtonStyling = {
3030
$$main: '$colors$primary',
3131
$$mainHover: '$colors$primaryHighlight',
3232
$$contrast: '$colors$primaryContrast',
@@ -135,7 +135,9 @@ export const StyledIconButton = styled(DEFAULT_TAG, {
135135
destructive: 'false',
136136
size: 'default',
137137
},
138-
})
138+
}
139+
140+
export const StyledIconButton = styled(DEFAULT_TAG, IconButtonStyling)
139141

140142
type IconButtonVariants = VariantProps<typeof StyledIconButton>
141143
type ButtonProps = ComponentProps<typeof DEFAULT_TAG>

src/components/Toggle/Toggle.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111

1212
const Template: ComponentStory<typeof Toggle> = ({ ...args }) => {
1313
return (
14-
<Toggle aria-label="Toggle italic">
14+
<Toggle aria-label="Toggle italic" {...args}>
1515
<Italic />
1616
</Toggle>
1717
)

src/components/Toggle/Toggle.tsx

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import * as TogglePrimitive from '@radix-ui/react-toggle'
22
import React, { ComponentProps, ElementRef, forwardRef } from 'react'
33
import type { AsProps, CSSProps, VariantProps } from '../../stitches.config'
44
import { styled } from '../../stitches.config'
5-
import { disabled, hover } from '../IconButton'
5+
import { hover, IconButtonStyling } from '../IconButton'
66

77
export const selected = {
88
backgroundColor: '$$onBackgroundColor',
99
color: '$$onColor',
10-
$$focusColor: '$$onFocusColor',
1110
}
1211

1312
const focus = hover
1413

1514
// TODO: pressed + hover together not working as intended
1615
export const ToggleStyling = {
16+
...IconButtonStyling,
1717
$$main: '$colors$primary',
1818
$$mainHover: '$colors$primaryHighlight',
1919
$$contrast: '$colors$primaryContrast',
@@ -23,45 +23,7 @@ export const ToggleStyling = {
2323
$$lowlight: '$colors$defaultLowlight',
2424
$$onBackgroundColor: '$color$defaultHighlight',
2525
$$onColor: '$$main',
26-
$$focusColor: '$$default',
2726

28-
// Reset
29-
alignItems: 'center',
30-
appearance: 'none',
31-
boxSizing: 'border-box',
32-
display: 'inline-flex',
33-
flexShrink: 0,
34-
justifyContent: 'center',
35-
lineHeight: '$none',
36-
margin: '0',
37-
outline: 'none',
38-
padding: '0',
39-
textDecoration: 'none',
40-
userSelect: 'none',
41-
WebkitTapHighlightColor: 'rgba(0,0,0,0)',
42-
'&::before': {
43-
boxSizing: 'border-box',
44-
},
45-
'&::after': {
46-
boxSizing: 'border-box',
47-
},
48-
49-
// Defaults
50-
fontSize: '$0',
51-
borderRadius: '$default',
52-
cursor: 'pointer',
53-
backgroundColor: 'transparent',
54-
border: 'none',
55-
56-
// Actions
57-
'@motion': {
58-
transition: 'background 0.5s',
59-
},
60-
backgroundPosition: 'center',
61-
62-
'&:hover': hover,
63-
'&:focus': focus,
64-
'&:disabled': disabled,
6527
'&[data-state=on]': selected,
6628

6729
variants: {

src/components/ToggleGroup/ToggleGroup.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const Template: Story<typeof ToggleGroup> = ({ ...args }) => {
2424
type="single"
2525
defaultValue="center"
2626
aria-label="Text alignment"
27+
{...args}
2728
>
2829
<ToggleGroupItem value="left" aria-label="Left aligned">
2930
<TextAlignLeft />

0 commit comments

Comments
 (0)