Skip to content

Commit

Permalink
Merge pull request #9 from BQXBQX/dev-max
Browse files Browse the repository at this point in the history
feat: combine shadow into one variable
  • Loading branch information
BQXBQX committed Feb 3, 2024
2 parents d513537 + 0ca740e commit c63ab90
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 25 deletions.
20 changes: 9 additions & 11 deletions packages/ui/lib/Button/Button.module.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@use '../variables' as *;
.base {
background-color: var(--primary-color);
color: white;
Expand All @@ -8,15 +9,7 @@
font-size: 16px;
font-weight: 400;
transition: all 0.15s ease-in-out;
&.shadow {
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
&:hover {
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
}
&:active {
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}
}
@include shadow;
&:hover {
backdrop-filter: brightness(0.85);
}
Expand All @@ -31,8 +24,13 @@
color: var(--primary-color);
border: 1px solid var(--primary-color);
}
&.tertiary {
background-color: #f6f6f6;
&.ghost {
&:hover {
// background-color: #ffffffc4;
filter: brightness(1);
backdrop-filter: brightness(0.97);
}
background-color: transparent;
color: var(--primary-color);
font-weight: 600;
}
Expand Down
7 changes: 5 additions & 2 deletions packages/ui/lib/Button/Button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ const meta = {
tags: ['autodocs'],
argTypes: {
color: {
options: ['primary', 'secondary', 'tertiary', 'danger'],
options: ['primary', 'secondary', 'ghost', 'danger'],
control: { type: 'select' },
},
size: {
options: ['small', 'medium', 'large'],
control: { type: 'select' },
},
shadow: {
options: ['regular', 'small', 'medium', 'large', 'extraLarge', 'inner', 'none'],
control: { type: 'select' },
},
},
} satisfies Meta<typeof Button>;

Expand All @@ -29,7 +33,6 @@ type Story = StoryObj<typeof meta>;
const defaultProps: ButtonProps = {
color: 'primary',
size: 'medium',
isShadow: false,
};

export const DefaultButton: Story = {
Expand Down
16 changes: 7 additions & 9 deletions packages/ui/lib/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,29 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
/**
* The color of the button.
*/
color?: 'primary' | 'secondary' | 'tertiary' | 'danger';

color?: 'primary' | 'secondary' | 'ghost' | 'danger';
/**
* The size of the button.
*/
size?: 'small' | 'medium' | 'large';

/**
* If `true`, the button will be disabled.
* The shadow of the button.
*/
disabled?: boolean;
shadow?: 'regular' | 'small' | 'medium' | 'large' | 'extraLarge' | 'inner' | 'none';
/**
* If `true`, the shadow will be appear
* If `true`, the button will be disabled.
*/
isShadow?: boolean;
disabled?: boolean;
}

export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ color = 'primary', size = 'medium', disabled = false, isShadow = false, ...rest }, ref) => {
({ color = 'primary', shadow = 'none', size = 'medium', disabled = false, ...rest }, ref) => {
const btnClass = classnames(
styles['base'],
styles[color],
styles[size],
styles[disabled ? 'disabled' : ''],
styles[isShadow ? 'shadow' : ''],
styles[`shadow-${shadow}`],
);
return (
<button
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/lib/Card/Card.module.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@use '../variables' as *;
.base {
height: fit-content;
border-radius: 6px;
Expand Down Expand Up @@ -46,15 +47,14 @@
width: 100%;
display: flex;
}
@include shadow;
&.light {
background-color: var(--white-color);
color: var(--black-color);
box-shadow: 1px 1px 4px 0px var(--shadow-color);
}
&.dark {
background-color: var(--dark-color);
color: var(--white-color);
box-shadow: 1px 1px 4px 0px var(--dark-color);
}
&.small {
width: 300px;
Expand Down
5 changes: 5 additions & 0 deletions packages/ui/lib/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const meta = {
options: ['small', 'medium', 'large'],
control: { type: 'select' },
},
shadow: {
options: ['regular', 'small', 'medium', 'large', 'extraLarge', 'inner'],
control: { type: 'select' },
},
},
} satisfies Meta<typeof Card>;

Expand All @@ -32,6 +36,7 @@ const defaultProps: CardProps = {
titleImage: undefined,
theme: 'light',
size: 'medium',
shadow: 'medium',
header: <span>header</span>,
content: <span>content</span>,
footer: <span>footer</span>,
Expand Down
7 changes: 6 additions & 1 deletion packages/ui/lib/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export interface CardProps {
* The size of the Card.
*/
size?: 'small' | 'medium' | 'large';
/**
* The shadow of the Card.
*/
shadow?: 'regular' | 'small' | 'medium' | 'large' | 'extraLarge' | 'inner';
/**
* The Header of the Card.
*/
Expand All @@ -34,6 +38,7 @@ export const Card = React.forwardRef<HTMLDivElement, CardProps>(
{
theme = 'light',
size = 'medium',
shadow = 'medium',
header = <span>header</span>,
content = <span>content</span>,
footer = <span>footer</span>,
Expand All @@ -42,7 +47,7 @@ export const Card = React.forwardRef<HTMLDivElement, CardProps>(
},
ref,
) => {
const cardClass = classnames(styles['base'], styles[theme], styles[size]);
const cardClass = classnames(styles['base'], styles[theme], styles[size], styles[`shadow-${shadow}`]);

return (
<div
Expand Down
39 changes: 39 additions & 0 deletions packages/ui/lib/_variables.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// box-shadow variables
$shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
$shadow:
0 1px 3px 0 rgba(0, 0, 0, 0.1),
0 1px 2px -1px rgba(0, 0, 0, 0.1);
$shadow-md:
0 4px 6px -1px rgb(0 0 0 / 0.1),
0 2px 4px -2px rgb(0 0 0 / 0.1);
$shadow-lg:
0 10px 15px -3px rgb(0 0 0 / 0.1),
0 4px 6px -4px rgb(0 0 0 / 0.1);
$shadow-xl:
0 20px 25px -5px rgb(0 0 0 / 0.1),
0 8px 10px -6px rgb(0 0 0 / 0.1);
$shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
$shadow-inner: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);

@mixin shadow {
&.shadow-regular {
box-shadow: $shadow;
}
&.shadow-small {
box-shadow: $shadow-sm;
}
&.shadow-medium {
box-shadow: $shadow-md;
}
&.shadow-large {
box-shadow: $shadow-lg;
}
&.shadow-extraLarge {
box-shadow: $shadow-xl;
}
&.shadow-inner {
box-shadow: $shadow-inner;
}
}

// border variables
3 changes: 3 additions & 0 deletions packages/ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
"noUnusedLocals": false,
"noUnusedParameters": true
},
"paths": {
"@/*": ["./lib/*"]
},
"include": ["./lib/**/*.ts", "./lib/**/*.tsx", "lib/Toast/showToast.js"],
"exclude": ["./lib/**/*.stories.*"]
}

0 comments on commit c63ab90

Please sign in to comment.