Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 13cb496

Browse files
authored
Merge pull request #32 from supabase/fix/button-fixes
Fix/button fixes
2 parents fb6dde4 + 6142d31 commit 13cb496

File tree

9 files changed

+231
-212
lines changed

9 files changed

+231
-212
lines changed

src/components/Button/Button.css

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
.sbui-btn-container {
2-
@apply inline-flex;
2+
@apply inline-flex font-medium;
33
}
44

55
.sbui-btn {
6-
@apply font-medium rounded;
7-
@apply relative cursor-pointer inline-flex space-x-2 text-center border border-solid border-transparent transition ease-out duration-200;
6+
@apply relative cursor-pointer inline-flex items-center space-x-2 text-center border border-solid border-transparent transition ease-out duration-200;
7+
@apply rounded;
88
font-family: inherit;
9+
font-weight: inherit;
910
text-shadow: 0 -1px 0 rgba(0,0,0,.12);
10-
-webkit-box-shadow: 0 2px 0 rgba(0,0,0,.045);
1111
}
1212

1313
.sbui-btn-container--shadow {
@@ -86,8 +86,15 @@
8686
}
8787

8888
.sbui-btn-primary.sbui-btn--danger {
89-
@apply bg-red-500 text-white
89+
@apply bg-red-500 text-white;
90+
@apply hover:bg-red-600 hover:border-red-600;
9091
}
92+
.sbui-btn-default.sbui-btn--danger, .sbui-btn-secondary.sbui-btn--danger, .sbui-btn-outline.sbui-btn--danger, .sbui-btn-dashed.sbui-btn--danger, .sbui-btn-link.sbui-btn--danger, .sbui-btn-text.sbui-btn--danger {
93+
@apply hover:bg-red-600 hover:text-white hover:border-red-600;
94+
}
95+
/* {
96+
@apply hover:bg-red-600 hover:text-white hover:border-red-600;
97+
} */
9198

9299
/*
93100
Animation for icon
@@ -112,35 +119,3 @@
112119
transform: rotate(360deg);
113120
}
114121
}
115-
116-
/*
117-
Puesdo classes
118-
*/
119-
120-
.btn:focus {
121-
@apply outline-none ring;
122-
}
123-
124-
/* .sbui-btn-primary:hover svg {
125-
@apply text-gray-500;
126-
}
127-
.sbui-btn-secondary:hover svg {
128-
@apply text-gray-100;
129-
}
130-
.sbui-btn-default:hover svg {
131-
@apply text-gray-300;
132-
}
133-
.sbui-btn-outline:hover svg {
134-
@apply text-white;
135-
}
136-
.sbui-btn-ghost:hover svg {
137-
@apply bg-brand-300;
138-
} */
139-
140-
.sbui-btn--with-icon {
141-
/* @apply pl-10; */
142-
}
143-
144-
.sbui-btn-icon-container {
145-
@apply inset-y-0 flex items-center pointer-events-none;
146-
}

src/components/Button/Button.js

Lines changed: 0 additions & 109 deletions
This file was deleted.

src/components/Button/Button.stories.js

Lines changed: 0 additions & 42 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react'
2+
3+
import { Button } from '.'
4+
import { Icon } from '../Icon'
5+
6+
export default {
7+
title: 'General/Button',
8+
component: Button,
9+
}
10+
11+
export const Default = (args: any) => <Button {...args}>Button text</Button>
12+
export const withStyles = (args: any) => <Button {...args}>Button text</Button>
13+
export const withIcon = (args: any) => <Button {...args}>Button text</Button>
14+
export const withIconRight = (args: any) => <Button {...args}>Button text</Button>
15+
export const withBlock = (args: any) => <Button {...args}>Button text</Button>
16+
export const withOnlyIcon = (args: any) => <Button {...args}/>
17+
export const withOnlyLoading = (args: any) => <Button {...args}/>
18+
19+
const icon = <Icon type={"Package"}/>
20+
21+
withIcon.args = {
22+
type: 'primary',
23+
icon: icon,
24+
}
25+
26+
withIconRight.args = {
27+
type: 'primary',
28+
iconRight: <Icon type={"ChevronRight"} strokeWidth={2}/>,
29+
}
30+
31+
withStyles.args = {
32+
type: 'primary',
33+
style: {backgroundColor: 'red', color: 'yellow'}
34+
}
35+
36+
withBlock.args = {
37+
type: 'primary',
38+
block: true
39+
}
40+
41+
withOnlyIcon.args = {
42+
icon: icon
43+
}
44+
45+
withOnlyLoading.args = {
46+
loading: true
47+
}

src/components/Button/Button.tsx

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import React from 'react'
2+
import PropTypes, { bool } from 'prop-types'
3+
import './Button.css'
4+
// @ts-ignore
5+
import { Transition, Icon } from '../../index'
6+
import { IconContext } from '../Icon/IconContext'
7+
8+
interface Props {
9+
block: boolean
10+
className: any
11+
children: React.ReactNode
12+
disabled: boolean
13+
onClick?: React.MouseEventHandler<HTMLButtonElement>
14+
icon?: React.ReactNode
15+
iconRight?: React.ReactNode
16+
loading?: boolean
17+
shadow?: boolean
18+
size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge'
19+
style?: React.CSSProperties
20+
type?:
21+
| 'primary'
22+
| 'default'
23+
| 'secondary'
24+
| 'outline'
25+
| 'dashed'
26+
| 'link'
27+
| 'text'
28+
danger: boolean
29+
spaceSize: number
30+
}
31+
32+
const Button = ({
33+
block,
34+
className,
35+
children,
36+
disabled = false,
37+
onClick,
38+
icon,
39+
iconRight,
40+
loading = false,
41+
shadow = true,
42+
size = 'medium',
43+
style,
44+
type = 'primary',
45+
danger,
46+
spaceSize,
47+
}: Props) => {
48+
let classes = []
49+
let containerClasses = ['sbui-btn-container']
50+
51+
if (block) {
52+
containerClasses.push('sbui-btn--w-full')
53+
classes.push('sbui-btn--w-full')
54+
}
55+
56+
if (danger) {
57+
classes.push('sbui-btn--danger')
58+
}
59+
60+
if (shadow) {
61+
classes.push('sbui-btn-container--shadow')
62+
}
63+
64+
if (size) {
65+
classes.push(`sbui-btn--${size}`)
66+
}
67+
68+
classes.push(`sbui-btn-${type}`)
69+
70+
const showIcon = loading || icon
71+
72+
return (
73+
<React.Fragment>
74+
<span className={containerClasses.join(' ')}>
75+
<button
76+
className={`sbui-btn ${classes.join(' ')} ${classes.join(
77+
' '
78+
)} ${className}`}
79+
disabled={loading || (disabled && true)}
80+
onClick={onClick}
81+
style={style}
82+
type="button"
83+
>
84+
{showIcon &&
85+
(loading ? (
86+
<Icon
87+
size={size}
88+
className={'sbui-btn--anim--spin'}
89+
type={'Loader'}
90+
/>
91+
) : icon ? (
92+
<IconContext.Provider value={{ contextSize: size }}>
93+
{icon}
94+
</IconContext.Provider>
95+
) : null)}
96+
{children && <span>{children}</span>}
97+
{iconRight && !loading && (
98+
<IconContext.Provider value={{ contextSize: size }}>
99+
{iconRight}
100+
</IconContext.Provider>
101+
)}
102+
</button>
103+
</span>
104+
</React.Fragment>
105+
)
106+
}
107+
108+
export default Button
File renamed without changes.

0 commit comments

Comments
 (0)