Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AlphaButton component #2182

Merged
merged 25 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
99d5483
feat(alpha-button): add types
yangwooseong Apr 24, 2024
bfe1c7c
feat(alpha-button): define style by color, variant, size
yangwooseong Apr 25, 2024
e36c619
feat(alpha-button): add icon
yangwooseong Apr 25, 2024
5d42643
feat(alpha-button): add color for icon and text
yangwooseong Apr 25, 2024
8f9fbc6
feat(alpha-button): add spinner
yangwooseong Apr 25, 2024
3bf4d31
feat(alpha-button): fix ButtonContent gap to ButtonText padding, add …
yangwooseong Apr 25, 2024
ca0eeff
feat(alpha-=button): add typography
yangwooseong Apr 25, 2024
7f4ad74
feat(alpha-button): apply color to spinner as well
yangwooseong Apr 25, 2024
d387ea7
feat(alpha-button): apply active, hover style
yangwooseong Apr 26, 2024
1bf926d
feat(alpha-button): export Button
yangwooseong Apr 26, 2024
cdb8bfd
feat(alpha-button): add simple storybook
yangwooseong Apr 26, 2024
29280e0
chore(changeset): add
yangwooseong Apr 26, 2024
a7a63d8
refactor(alpha-button): move type props into rest
yangwooseong Apr 29, 2024
a2ddbcb
feat(button,alpha-button): change focus-visible style
yangwooseong Apr 29, 2024
5d95d90
chore(changeset): add
yangwooseong Apr 29, 2024
787c722
feat(alpha-button): rm floating from variant props, etc
yangwooseong Apr 29, 2024
3c94977
feat(alpha-button): resolve typecheck, lint error and rename type
yangwooseong Apr 29, 2024
43e6a3c
chore(alpha-button): add comment
yangwooseong Apr 29, 2024
484529a
feat(alpha-button): add missed transition property
yangwooseong Apr 29, 2024
a918a38
fix(alpha-button): fix typo in transition property
yangwooseong Apr 29, 2024
958f7c2
refactor(alpha-button): rm for loop, instead overide previously defin…
yangwooseong Apr 29, 2024
316a018
refactor(alpha-button): cover `disabled` in rest props
yangwooseong Apr 29, 2024
f61f019
feat(alpha-button): fix bg color of secondary, rm redundant :not sele…
yangwooseong Apr 29, 2024
96933f4
refactor(alpha-button): add &: to nested selector for consistence
yangwooseong Apr 29, 2024
f58e049
feat(alpha-button): make text props required
yangwooseong Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/forty-days-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@channel.io/bezier-react": patch
---

Change outline color of primary and blue `Button` component when focused.
5 changes: 5 additions & 0 deletions .changeset/olive-ants-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@channel.io/bezier-react": patch
---

Add `AlphaButton` component.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ArrowRightIcon, PlusIcon } from '@channel.io/bezier-icons'
import { type Meta, type StoryObj } from '@storybook/react'

import {
AlphaButton,
type AlphaButtonProps,
} from '~/src/components/AlphaButton'

const meta: Meta<typeof AlphaButton> = {
component: AlphaButton,
argTypes: {
onClick: { action: 'onClick' },
},
}
export default meta

export const Playground: StoryObj<AlphaButtonProps> = {
args: {
text: 'Invite',
disabled: false,
active: false,
loading: false,
prefixIcon: PlusIcon,
suffixIcon: ArrowRightIcon,
size: 'm',
variant: 'primary',
color: 'blue',
},
}
267 changes: 267 additions & 0 deletions packages/bezier-react/src/components/AlphaButton/Button.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
$chromatic-colors: 'blue', 'red', 'green', 'cobalt', 'orange', 'pink', 'purple';

.Button {
position: relative;
box-sizing: border-box;
transition: background-color var(--transition-s);

/* dimension */
&:where(.size-xs) {
height: 20px;
padding: 0 4px;

& :where(.ButtonText) {
padding: 0 3px;
}
}

&:where(.size-s) {
height: 24px;
padding: 0 6px;

& :where(.ButtonText) {
padding: 0 3px;
}

& :where(.ButtonContent) {
gap: 1px;
}
}

&:where(.size-m) {
height: 36px;
padding: 0 10px;

& :where(.ButtonText) {
padding: 0 4px;
}
}

&:where(.size-l) {
height: 44px;
padding: 0 14px;

& :where(.ButtonText) {
padding: 0 6px;
}
}

&:where(.size-xl) {
height: 54px;
padding: 0 18px;

& :where(.ButtonText) {
padding: 0 6px;
}
}

/* background-color */
&:where(.variant-primary) {
$background-color-by-color: (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

blue: var(--alpha-color-primary-bg-normal),
cobalt: var(--alpha-color-accent-bg-normal),
red: var(--alpha-color-critical-bg-normal),
orange: var(--alpha-color-warning-bg-normal),
green: var(--alpha-color-success-bg-normal),
pink: var(--alpha-color-bg-pink-normal),
purple: var(--alpha-color-bg-purple-normal),
dark-grey: var(--alpha-color-bg-grey-darkest),
light-grey: var(--alpha-color-bg-black-dark),
);

@each $color, $background-color in $background-color-by-color {
&:where(.color-#{$color}) {
background-color: $background-color;
}
}
}

&:where(.variant-secondary) {
$background-color-by-color: (
blue: var(--alpha-color-primary-bg-lightest),
cobalt: var(--alpha-color-accent-bg-lightest),
red: var(--alpha-color-critical-bg-lightest),
orange: var(--alpha-color-warning-bg-lightest),
green: var(--alpha-color-success-bg-lightest),
pink: var(--alpha-color-bg-pink-lightest),
purple: var(--alpha-color-bg-purple-lightest),
dark-grey: var(--alpha-color-bg-black-lighter),
light-grey: var(--alpha-color-bg-black-lighter),
);

@each $color, $background-color in $background-color-by-color {
&:where(.color-#{$color}) {
background-color: $background-color;
}
}
}

&:where(.variant-tertiary) {
background-color: initial;
}

/* color */
/* stylelint-disable-next-line no-duplicate-selectors */
&:where(.variant-primary) {
color: var(--alpha-color-fg-absolute-white-dark);

&:where(.color-dark-grey) {
color: var(--alpha-color-fg-white-normal);
}

&:where(.color-light-grey) {
color: var(--alpha-color-fg-absolute-white-normal);
}
}

&:where(.variant-secondary, .variant-tertiary) {
$color-map: (
blue: var(--alpha-color-primary-fg-normal),
cobalt: var(--alpha-color-accent-fg-normal),
red: var(--alpha-color-critical-fg-normal),
orange: var(--alpha-color-warning-fg-normal),
green: var(--alpha-color-success-fg-normal),
pink: var(--alpha-color-fg-pink-normal),
purple: var(--alpha-color-fg-purple-normal),
dark-grey: var(--alpha-color-fg-black-darkest),
light-grey: var(--alpha-color-fg-black-darker),
);

@each $button-color, $color in $color-map {
&:where(.color-#{$button-color}) {
color: $color;
}
}

&:where(.color-dark-grey) {
& :where(.ButtonIcon) {
color: var(--alpha-color-fg-black-darker);
}
}

&:where(.color-light-grey) {
& :where(.ButtonIcon) {
color: var(--alpha-color-fg-black-dark);
}
}
}

&:where(.variant-tertiary.color-white) {
& :where(.ButtonIcon) {
color: var(--alpha-color-fg-absolute-white-light);
}

& :where(.ButtonText) {
color: var(--alpha-color-fg-absolute-white-normal);
}
}

/* border-radius */
&:where(.variant-primary, .variant-secondary, .variant-tertiary) {
$border-radius-by-size: (
xs: var(--alpha-dimension-6),
s: var(--alpha-dimension-7),
m: var(--alpha-dimension-10),
l: var(--alpha-dimension-12),
xl: var(--alpha-dimension-14),
);

@each $size, $border-radius in $border-radius-by-size {
&:where(.size-#{$size}) {
border-radius: $border-radius;
}
}
}

/* TODO: use v2 token when design is specified */

/* visual effect on interaction */
&:where(.active, :hover):where(:not(:disabled)) {
&:where(.variant-primary) {
@each $color in $chromatic-colors {
&:where(.color-#{$color}) {
background-color: var(--bgtxt-#{$color}-dark);
}
}

&:where(.color-dark-grey) {
background-color: var(--bg-grey-darkest);
}

&:where(.color-light-grey) {
background-color: var(--bg-black-darker);
}
}

&:where(.variant-secondary) {
@each $color in $chromatic-colors {
&:where(.color-#{$color}) {
background-color: var(--bgtxt-#{$color}-lighter);
}
}

&:where(.color-dark-grey, .color-light-grey) {
background-color: var(--bg-black-light);
}
}

&:where(.variant-tertiary) {
@each $color in $chromatic-colors {
&:where(.color-#{$color}) {
background-color: var(--bgtxt-#{$color}-lightest);
}
}

&:where(.color-dark-grey, .color-light-grey, .color-white) {
background-color: var(--bg-black-lighter);
}
}

&:where(.color-dark-grey):where(.variant-secondary, .variant-tertiary) {
& :is(.ButtonIcon, .ButtonLoader) {
color: var(--txt-black-darkest);
}
}

&:where(.color-light-grey):where(.variant-secondary, .variant-tertiary) {
& :is(.ButtonIcon, .ButtonLoader) {
color: var(--txt-black-darker);
}
}

&:where(.color-white.variant-tertiary) {
& :where(.ButtonIcon) {
color: var(--alpha-color-fg-absolute-white-normal);
}
}
}

&:where(.variant-primary.color-blue:focus-visible) {
outline: 3px solid var(--bgtxt-blue-light);
}

&:disabled {
cursor: not-allowed;
opacity: var(--alpha-opacity-disabled);
}

/* internal components */
.ButtonContent {
display: flex;
align-items: center;
justify-content: center;

&:where(.loading) {
visibility: hidden;
}
}

.ButtonLoader {
position: absolute;
inset: 0;

display: flex;
align-items: center;
justify-content: center;
}
}
Loading
Loading