Skip to content

Commit af5cb6f

Browse files
authored
Add floating-alt style variant in Button element (#907)
* feat: add floating alt style variant in Button element * test: add snapshot * docs: add changeset * fix: floating style elevation * docs: update button mdx * fix: button border radius
1 parent 545a18c commit af5cb6f

File tree

6 files changed

+175
-16
lines changed

6 files changed

+175
-16
lines changed

.changeset/heavy-jars-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@channel.io/bezier-react": patch
3+
---
4+
5+
Add floating-alt style variant in Button element

packages/bezier-react/src/components/Button/Button.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ enum ButtonStyleVariant {
253253
Secondary,
254254
Tertiary,
255255
Floating,
256+
FloatingAlt,
256257
}
257258
```
258259
</details>

packages/bezier-react/src/components/Button/Button.styled.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* External dependencies */
2-
import { isEmpty } from 'lodash-es'
2+
import { isEmpty, includes } from 'lodash-es'
33

44
/* Internal dependencies */
55
import { styled, css, SemanticNames } from 'Foundation'
@@ -96,7 +96,9 @@ function getPaddingCSSFromSizeAndContents({
9696
`
9797
}
9898

99-
const paddingVariant = styleVariant !== ButtonStyleVariant.Floating ? 'default' : 'floating'
99+
const paddingVariant = includes([ButtonStyleVariant.Floating, ButtonStyleVariant.FloatingAlt], styleVariant)
100+
? 'floating'
101+
: 'default'
100102

101103
const paddingValue = BUTTON_HORIZONTAL_PADDING_VALUE[size][paddingVariant]
102104

@@ -148,6 +150,12 @@ function defaultSemanticNames(colorVariant: ButtonColorVariant): Record<ButtonSt
148150
backgroundColor: `bgtxt-${colorVariant}-normal` as const,
149151
activeBackgroundColor: `bgtxt-${colorVariant}-dark` as const,
150152
},
153+
154+
[ButtonStyleVariant.FloatingAlt]: {
155+
color: 'bgtxt-absolute-white-dark',
156+
backgroundColor: `bgtxt-${colorVariant}-normal` as const,
157+
activeBackgroundColor: `bgtxt-${colorVariant}-dark` as const,
158+
},
151159
}
152160
}
153161

@@ -173,6 +181,10 @@ const MONOCHROME_SEMANTIC_NAMES: Record<ButtonStyleVariant, ButtonSemanticNames>
173181
[ButtonStyleVariant.Floating]: {
174182
color: 'txt-black-darkest',
175183
},
184+
185+
[ButtonStyleVariant.FloatingAlt]: {
186+
color: 'txt-black-darkest',
187+
},
176188
}
177189

178190
const MONOCHROME_LIGHT_SEMANTIC_NAMES: Record<ButtonStyleVariant, ButtonSemanticNames> = {
@@ -197,6 +209,11 @@ const MONOCHROME_LIGHT_SEMANTIC_NAMES: Record<ButtonStyleVariant, ButtonSemantic
197209
color: 'txt-black-darker',
198210
backgroundColor: 'bg-white-high',
199211
},
212+
213+
[ButtonStyleVariant.FloatingAlt]: {
214+
color: 'txt-black-darker',
215+
backgroundColor: 'bg-white-high',
216+
},
200217
}
201218

202219
const MONOCHROME_DARK_SEMANTIC_NAMES: Record<ButtonStyleVariant, ButtonSemanticNames> = {
@@ -221,6 +238,11 @@ const MONOCHROME_DARK_SEMANTIC_NAMES: Record<ButtonStyleVariant, ButtonSemanticN
221238
color: 'txt-black-darkest',
222239
backgroundColor: 'bg-white-high',
223240
},
241+
242+
[ButtonStyleVariant.FloatingAlt]: {
243+
color: 'txt-black-darkest',
244+
backgroundColor: 'bg-white-high',
245+
},
224246
}
225247

226248
function getColorCSS(
@@ -275,13 +297,22 @@ function getEffectCSSFromVariant(styleVariant: ButtonProps['styleVariant'], size
275297
switch (styleVariant) {
276298
case ButtonStyleVariant.Floating:
277299
return css`
278-
${({ foundation }) => foundation?.elevation?.ev3()};
300+
${({ foundation }) => foundation?.elevation?.ev2()};
279301
/* NOTE: height 기반의 100% border-radius 를 사용하기 위해, foundation rounding 을 무시한 hack */
280302
overflow: hidden;
281303
border-radius: 1000px;
282304
283305
&:hover {
284-
${({ foundation }) => foundation?.elevation?.ev4()};
306+
${({ foundation }) => foundation?.elevation?.ev3()};
307+
}
308+
`
309+
case ButtonStyleVariant.FloatingAlt:
310+
return css`
311+
${({ foundation }) => foundation?.elevation?.ev2()};
312+
${({ foundation }) => foundation?.rounding?.round8};
313+
314+
&:hover {
315+
${({ foundation }) => foundation?.elevation?.ev3()};
285316
}
286317
`
287318
case ButtonStyleVariant.Tertiary:

packages/bezier-react/src/components/Button/Button.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ describe('Button Test >', () => {
8989

9090
expect(floatingButton).toMatchSnapshot()
9191
})
92+
93+
it('FloatingAlt', () => {
94+
const { getByTestId } = renderButton({ styleVariant: ButtonStyleVariant.FloatingAlt })
95+
const floatingAltButton = getByTestId(BUTTON_TEST_ID)
96+
const mButtonPaddingFloating = BUTTON_HORIZONTAL_PADDING_VALUE[ButtonSize.M].floating
97+
98+
// Colors
99+
expect(floatingAltButton).toHaveStyle(`color: ${LightFoundation.theme['bgtxt-absolute-white-dark']}`)
100+
expect(floatingAltButton).toHaveStyle(`background-color: ${LightFoundation.theme['bgtxt-blue-normal']}`)
101+
expect(floatingAltButton).toHaveStyle('border-radius: 8px;')
102+
103+
// Padding
104+
expect(floatingAltButton).toHaveStyle(`padding: 0 ${mButtonPaddingFloating}px 0 ${mButtonPaddingFloating}px;`)
105+
106+
expect(floatingAltButton).toMatchSnapshot()
107+
})
92108
})
93109

94110
describe('Disabled Test >', () => {

packages/bezier-react/src/components/Button/Button.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export enum ButtonStyleVariant {
77
Secondary = 'secondary',
88
Tertiary = 'tertiary',
99
Floating = 'floating',
10+
FloatingAlt = 'floating-alt',
1011
}
1112

1213
export enum ButtonColorVariant {

packages/bezier-react/src/components/Button/__snapshots__/Button.test.tsx.snap

Lines changed: 117 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ exports[`Button Test > Size Test > with text > Size L - styleVariant: Floating 1
492492
height: 44px;
493493
padding: 0 18px 0 18px;
494494
background-color: #FFFFFF;
495-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
495+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 2px 6px #00000014;
496496
overflow: hidden;
497497
border-radius: 1000px;
498498
color: #FFFFFF;
@@ -501,7 +501,7 @@ exports[`Button Test > Size Test > with text > Size L - styleVariant: Floating 1
501501
502502
.c0:hover {
503503
background-color: #FFFFFF;
504-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 20px #00000038;
504+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
505505
}
506506
507507
.c0:hover {
@@ -699,7 +699,7 @@ exports[`Button Test > Size Test > with text > Size M - styleVariant: Floating 1
699699
height: 36px;
700700
padding: 0 14px 0 14px;
701701
background-color: #FFFFFF;
702-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
702+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 2px 6px #00000014;
703703
overflow: hidden;
704704
border-radius: 1000px;
705705
color: #FFFFFF;
@@ -708,7 +708,7 @@ exports[`Button Test > Size Test > with text > Size M - styleVariant: Floating 1
708708
709709
.c0:hover {
710710
background-color: #FFFFFF;
711-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 20px #00000038;
711+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
712712
}
713713
714714
.c0:hover {
@@ -902,7 +902,7 @@ exports[`Button Test > Size Test > with text > Size S - styleVariant: Floating 1
902902
height: 24px;
903903
padding: 0 9px 0 9px;
904904
background-color: #FFFFFF;
905-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
905+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 2px 6px #00000014;
906906
overflow: hidden;
907907
border-radius: 1000px;
908908
color: #FFFFFF;
@@ -911,7 +911,7 @@ exports[`Button Test > Size Test > with text > Size S - styleVariant: Floating 1
911911
912912
.c0:hover {
913913
background-color: #FFFFFF;
914-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 20px #00000038;
914+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
915915
}
916916
917917
.c0:hover {
@@ -1105,7 +1105,7 @@ exports[`Button Test > Size Test > with text > Size XL - styleVariant: Floating
11051105
height: 54px;
11061106
padding: 0 23px 0 23px;
11071107
background-color: #FFFFFF;
1108-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
1108+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 2px 6px #00000014;
11091109
overflow: hidden;
11101110
border-radius: 1000px;
11111111
color: #FFFFFF;
@@ -1114,7 +1114,7 @@ exports[`Button Test > Size Test > with text > Size XL - styleVariant: Floating
11141114
11151115
.c0:hover {
11161116
background-color: #FFFFFF;
1117-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 20px #00000038;
1117+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
11181118
}
11191119
11201120
.c0:hover {
@@ -1308,7 +1308,7 @@ exports[`Button Test > Size Test > with text > Size XS - styleVariant: Floating
13081308
height: 20px;
13091309
padding: 0 7px 0 7px;
13101310
background-color: #FFFFFF;
1311-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
1311+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 2px 6px #00000014;
13121312
overflow: hidden;
13131313
border-radius: 1000px;
13141314
color: #FFFFFF;
@@ -1317,7 +1317,7 @@ exports[`Button Test > Size Test > with text > Size XS - styleVariant: Floating
13171317
13181318
.c0:hover {
13191319
background-color: #FFFFFF;
1320-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 20px #00000038;
1320+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
13211321
}
13221322
13231323
.c0:hover {
@@ -1959,7 +1959,7 @@ exports[`Button Test > StyleVariant Test > Floating 1`] = `
19591959
height: 36px;
19601960
padding: 0 14px 0 14px;
19611961
background-color: #FFFFFF;
1962-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
1962+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 2px 6px #00000014;
19631963
overflow: hidden;
19641964
border-radius: 1000px;
19651965
color: #FFFFFF;
@@ -1968,7 +1968,112 @@ exports[`Button Test > StyleVariant Test > Floating 1`] = `
19681968
19691969
.c0:hover {
19701970
background-color: #FFFFFF;
1971-
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 20px #00000038;
1971+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
1972+
}
1973+
1974+
.c0:hover {
1975+
background-color: #4E40C9;
1976+
}
1977+
1978+
.c3 {
1979+
padding: 0 4px;
1980+
}
1981+
1982+
@supports not(gap:2px) {
1983+
.c1 {
1984+
margin-top: -2px;
1985+
margin-left: -2px;
1986+
}
1987+
1988+
.c1 > * {
1989+
margin-top: 2px;
1990+
margin-left: 2px;
1991+
}
1992+
}
1993+
1994+
<button
1995+
class="c0"
1996+
data-testid="bezier-react-button"
1997+
type="button"
1998+
>
1999+
<div
2000+
class="c1"
2001+
data-testid="bezier-react-button-inner-content"
2002+
>
2003+
<span
2004+
class="c2 c3"
2005+
data-testid="bezier-react-button-text"
2006+
>
2007+
Test Button
2008+
</span>
2009+
</div>
2010+
</button>
2011+
`;
2012+
2013+
exports[`Button Test > StyleVariant Test > FloatingAlt 1`] = `
2014+
.c2 {
2015+
font-size: 1.4rem;
2016+
line-height: 1.8rem;
2017+
margin: 0px 0px 0px 0px;
2018+
font-style: normal;
2019+
font-weight: 600;
2020+
color: inherit;
2021+
-webkit-transition-delay: 0ms;
2022+
transition-delay: 0ms;
2023+
-webkit-transition-timing-function: cubic-bezier(.3,0,0,1);
2024+
transition-timing-function: cubic-bezier(.3,0,0,1);
2025+
-webkit-transition-duration: 150ms;
2026+
transition-duration: 150ms;
2027+
-webkit-transition-property: color;
2028+
transition-property: color;
2029+
}
2030+
2031+
.c1 {
2032+
display: -webkit-box;
2033+
display: -webkit-flex;
2034+
display: -ms-flexbox;
2035+
display: flex;
2036+
-webkit-align-items: center;
2037+
-webkit-box-align: center;
2038+
-ms-flex-align: center;
2039+
align-items: center;
2040+
-webkit-box-pack: center;
2041+
-webkit-justify-content: center;
2042+
-ms-flex-pack: center;
2043+
justify-content: center;
2044+
visibility: visible;
2045+
gap: 2px;
2046+
}
2047+
2048+
.c0 {
2049+
position: relative;
2050+
box-sizing: border-box;
2051+
cursor: pointer;
2052+
border: none;
2053+
outline: none;
2054+
opacity: 1;
2055+
-webkit-transition-delay: 0ms;
2056+
transition-delay: 0ms;
2057+
-webkit-transition-timing-function: cubic-bezier(.3,0,0,1);
2058+
transition-timing-function: cubic-bezier(.3,0,0,1);
2059+
-webkit-transition-duration: 150ms;
2060+
transition-duration: 150ms;
2061+
-webkit-transition-property: background-color,box-shadow;
2062+
transition-property: background-color,box-shadow;
2063+
min-width: 36px;
2064+
height: 36px;
2065+
padding: 0 14px 0 14px;
2066+
background-color: #FFFFFF;
2067+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 2px 6px #00000014;
2068+
overflow: hidden;
2069+
border-radius: 8px;
2070+
color: #FFFFFF;
2071+
background-color: #5E56F0;
2072+
}
2073+
2074+
.c0:hover {
2075+
background-color: #FFFFFF;
2076+
box-shadow: inset 0 0 2px 0 #FFFFFF1F, 0 0 2px 1px #0000000D, 0 4px 12px #00000026;
19722077
}
19732078
19742079
.c0:hover {

0 commit comments

Comments
 (0)