Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: add more button variant

Muhammad Rivkiaca8abb3a15d
diff --git a/supabase-ui/package.json b/supabase-ui/package.json
index d5b5d58f763..2de8b9dd90a 100644
--- a/supabase-ui/package.json
+++ b/supabase-ui/package.json
@@ -8,6 +8,7 @@
"scripts": {
"build": "NODE_ENV=production rollup -c",
"build-watch": "NODE_ENV=production rollup -c -w",
+ "test": "react-scripts test",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
},
@@ -16,7 +17,8 @@
"react-dom": "^16.13.1"
},
"dependencies": {
- "@headlessui/react": "^0.2.0"
+ "@headlessui/react": "^0.2.0",
+ "prop-types": "^15.7.2"
},
"devDependencies": {
"@babel/cli": "^7.11.6",
diff --git a/supabase-ui/src/components/Button/Button.css b/supabase-ui/src/components/Button/Button.css
index cf64b3845c1..3101fb02805 100644
--- a/supabase-ui/src/components/Button/Button.css
+++ b/supabase-ui/src/components/Button/Button.css
@@ -1,11 +1,45 @@
.btn {
- @apply cursor-pointer flex items-center justify-center px-8 py-3 border border-transparent text-base leading-6 font-medium rounded text-white bg-green-600 transition duration-150 ease-in-out;
+ @apply cursor-pointer flex items-center justify-center px-4 py-1 border border-transparent text-sm leading-6 rounded transition duration-150 ease-in-out;
}
.btn:focus {
@apply outline-none shadow-outline;
}
-.btn:hover {
- @apply bg-green-500;
+.btn:disabled {
+ @apply opacity-50 cursor-default;
+}
+
+/* SIZE */
+.btn--large {
+ @apply text-base px-6 py-2;
+}
+
+.btn--small {
+ @apply text-xs px-3 py-0;
+}
+
+/* VARIANT */
+.btn--solid {
+ @apply text-white bg-brand-500;
+}
+
+.btn--solid:hover {
+ @apply bg-brand-600;
+}
+
+.btn--outline {
+ @apply bg-transparent border border-brand-500 border-solid text-brand-500;
+}
+
+.btn--outline:hover {
+ @apply bg-brand-500 text-white;
+}
+
+.btn--ghost {
+ @apply bg-transparent text-brand-500 border-none;
+}
+
+.btn--ghost:hover {
+ @apply bg-brand-300 bg-opacity-25;
}
diff --git a/supabase-ui/src/components/Button/Button.js b/supabase-ui/src/components/Button/Button.js
index 5766ffe1c31..bf0afc60be9 100644
--- a/supabase-ui/src/components/Button/Button.js
+++ b/supabase-ui/src/components/Button/Button.js
@@ -1,8 +1,57 @@
import React from 'react'
+import PropTypes from 'prop-types'
import './Button.css'
-const Button = ({ className, children, ...props }) => (
- <button className="btn w-full">{children}</button>
-)
+export const SIZES = ['small', 'medium', 'large']
+export const VARIANTS = ['solid', 'outline', 'ghost']
+
+const Button = ({
+ className = '',
+ children,
+ block,
+ size = 'medium',
+ variant = 'solid',
+ ...props
+}) => {
+ let classes = []
+
+ if (block) {
+ classes.push('w-full')
+ }
+
+ if (size) {
+ let sizeClasses = {
+ small: 'btn--small',
+ medium: 'btn--medium',
+ large: 'btn--large',
+ }
+ classes.push(sizeClasses[size])
+ }
+
+ if (variant) {
+ let variantClasses = {
+ solid: 'btn--solid',
+ outline: 'btn--outline',
+ ghost: 'btn--ghost',
+ }
+
+ classes.push(variantClasses[variant])
+ }
+
+ return (
+ <button className={`btn ${classes.join(' ')} ${className}`} {...props}>
+ {children}
+ </button>
+ )
+}
+
+Button.propTypes = {
+ size: PropTypes.oneOf(SIZES),
+ variant: PropTypes.oneOf(VARIANTS),
+ block: PropTypes.bool,
+ outline: PropTypes.bool,
+ ghost: PropTypes.bool,
+ className: PropTypes.string,
+}
export default Button
diff --git a/supabase-ui/src/components/Button/Button.stories.js b/supabase-ui/src/components/Button/Button.stories.js
index 8b7bc46e1c1..fa318697f6a 100644
--- a/supabase-ui/src/components/Button/Button.stories.js
+++ b/supabase-ui/src/components/Button/Button.stories.js
@@ -7,4 +7,4 @@ export default {
component: Button,
}
-export const Primary = (args) => <Button>Some Children</Button>
+export const Default = (args) => <Button {...args}>Button</Button>
diff --git a/supabase-ui/src/components/Button/Button.test.js b/supabase-ui/src/components/Button/Button.test.js
new file mode 100644
index 00000000000..a86da9c0d1c
--- /dev/null
+++ b/supabase-ui/src/components/Button/Button.test.js
@@ -0,0 +1,27 @@
+import React from 'react'
+import { render, screen } from '@testing-library/react'
+import Button, { SIZES, VARIANTS } from './Button'
+
+describe('#Button', () => {
+ it('should render button correctly', async () => {
+ render(<Button>Button</Button>)
+ expect(screen.queryByText('Button')).toBeInTheDocument()
+ })
+
+ it('should have "w-full" class', async () => {
+ render(<Button block>Button Block</Button>)
+ expect(screen.queryByRole('button')).toHaveClass('btn w-full btn--medium')
+ })
+
+ it.each(VARIANTS)('should have "btn--%s" class', (variant) => {
+ render(<Button variant={variant}>Button Variant</Button>)
+ expect(screen.queryByRole('button')).toHaveClass(
+ `btn btn--medium btn--${variant}`
+ )
+ })
+
+ it.each(SIZES)('should have "btn--%s" class', (size) => {
+ render(<Button size={size}>Button</Button>)
+ expect(screen.queryByRole('button')).toHaveClass(`btn btn--${size}`)
+ })
+})