Skip to content

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

feat: add radio component

Muhammad Rivki9350106d6d75
diff --git a/supabase-ui/package.json b/supabase-ui/package.json
index 31c6914d1e5..4a8616d6e64 100644
--- a/supabase-ui/package.json
+++ b/supabase-ui/package.json
@@ -37,6 +37,7 @@
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.0.4",
"@testing-library/user-event": "^12.1.7",
+ "autoprefixer": "^10.0.1",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-add-react-displayname": "^0.0.5",
diff --git a/supabase-ui/src/components/Radio/Radio.css b/supabase-ui/src/components/Radio/Radio.css
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/supabase-ui/src/components/Radio/Radio.js b/supabase-ui/src/components/Radio/Radio.js
new file mode 100644
index 00000000000..df1a3adeb63
--- /dev/null
+++ b/supabase-ui/src/components/Radio/Radio.js
@@ -0,0 +1,26 @@
+import React from 'react'
+import PropTypes from 'prop-types'
+import './Radio.css'
+
+const Radio = ({
+ className = '',
+ label = '',
+ containerClassName = '',
+ children,
+ ...props
+}) => {
+
+ return (
+ <label className={`inline-flex items-center ${containerClassName}`}>
+ <input type="radio" className={`form-radio border-solid h-4 w-4 ${className}`} {...props} />
+ <span className="ml-2">{label}</span>
+ </label>
+ )
+}
+
+Radio.propTypes = {
+ label: PropTypes.string,
+ className: PropTypes.string,
+}
+
+export default Radio
diff --git a/supabase-ui/src/components/Radio/Radio.stories.js b/supabase-ui/src/components/Radio/Radio.stories.js
new file mode 100644
index 00000000000..7c6ef26c490
--- /dev/null
+++ b/supabase-ui/src/components/Radio/Radio.stories.js
@@ -0,0 +1,26 @@
+import React from 'react'
+
+import { Radio } from '.'
+
+export default {
+ title: 'Form/Radio',
+ component: Radio,
+}
+
+export const Default = (args) => (
+ <div className="block font-sans">
+ <div>
+ <Radio name="radio-group" label="JavaScript" {...args} />
+ </div>
+ <div>
+ <Radio name="radio-group" label="TypeScript" {...args} />
+ </div>
+ <div>
+ <Radio name="radio-group" label="ReScript" {...args} />
+ </div>
+ </div>
+)
+
+Default.args = {
+ disabled: false,
+}
diff --git a/supabase-ui/src/components/Radio/Radio.test.js b/supabase-ui/src/components/Radio/Radio.test.js
new file mode 100644
index 00000000000..7eaa33451b4
--- /dev/null
+++ b/supabase-ui/src/components/Radio/Radio.test.js
@@ -0,0 +1,19 @@
+import React from 'react'
+import { render, screen } from '@testing-library/react'
+import Radio from './Radio'
+
+describe('#Radio', () => {
+ it('should render radio correctly', () => {
+ render(
+ <Radio data-testid="form-radio" />
+ )
+ expect(screen.queryByTestId('form-radio')).toBeInTheDocument()
+ })
+
+ it('should show label', () => {
+ render(
+ <Radio data-testid="form-radio" label="JavaScript" />
+ )
+ expect(screen.queryByText('JavaScript')).toBeInTheDocument()
+ })
+})
\ No newline at end of file
diff --git a/supabase-ui/src/components/Radio/index.js b/supabase-ui/src/components/Radio/index.js
new file mode 100644
index 00000000000..e200e77534e
--- /dev/null
+++ b/supabase-ui/src/components/Radio/index.js
@@ -0,0 +1 @@
+export { default as Radio } from './Radio'
diff --git a/supabase-ui/yarn.lock b/supabase-ui/yarn.lock
index bccf19a07e4..6bfa832a254 100644
--- a/supabase-ui/yarn.lock
+++ b/supabase-ui/yarn.lock
@@ -4449,6 +4449,18 @@ atob@^2.1.2:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
integrity sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==
+autoprefixer@^10.0.1:
+ version "10.0.1"
+ resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.0.1.tgz#e2d9000f84ebd98d77b7bc16f8adb2ff1f7bb946"
+ integrity sha512-aQo2BDIsoOdemXUAOBpFv4ZQa2DrOtEufarYhtFsK1088Ca0TUwu/aQWf0M3mrILXZ3mTIVn1lR3hPW8acacsw==
+ dependencies:
+ browserslist "^4.14.5"
+ caniuse-lite "^1.0.30001137"
+ colorette "^1.2.1"
+ normalize-range "^0.1.2"
+ num2fraction "^1.2.2"
+ postcss-value-parser "^4.1.0"
+
autoprefixer@^9.4.5, autoprefixer@^9.7.2:
version "9.8.6"
resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-9.8.6.tgz#3b73594ca1bf9266320c5acf1588d74dea74210f"
@@ -5155,7 +5167,7 @@ [email protected], browserslist@^4.0.0, browserslist@^4.6.2, browserslist@^4.6
node-releases "^1.1.52"
pkg-up "^3.1.0"
-browserslist@^4.12.0:
+browserslist@^4.12.0, browserslist@^4.14.5:
version "4.14.5"
resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.14.5.tgz#1c751461a102ddc60e40993639b709be7f2c4015"
integrity sha512-Z+vsCZIvCBvqLoYkBFTwEYH3v5MCQbsAjp50ERycpOjnPmolg1Gjy4+KaWWpm8QOJt9GHkhdqAl14NpCX73CWA==
@@ -5366,6 +5378,11 @@ caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001020, can
resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001147.tgz"
integrity sha512-CPyN875geYk46eIqPl5jlmotCr5YZC2KxIVfb4z0FrNfLxPM+MyodWD2irJGDG8vUUE1fmg3De9vt8uaC6Nf6w==
+caniuse-lite@^1.0.30001137:
+ version "1.0.30001151"
+ resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001151.tgz#1ddfde5e6fff02aad7940b4edb7d3ac76b0cb00b"
+ integrity sha512-Zh3sHqskX6mHNrqUerh+fkf0N72cMxrmflzje/JyVImfpknscMnkeJrlFGJcqTmaa0iszdYptGpWMJCRQDkBVw==
+
capture-exit@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/capture-exit/-/capture-exit-2.0.0.tgz#fb953bfaebeb781f62898239dabb426d08a509a4"