mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 09:26:47 +00:00
feat(ui) added select, spinner components
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { themes } from '@storybook/theming';
|
||||||
import '../src/styles/globals.css';
|
import '../src/styles/globals.css';
|
||||||
|
|
||||||
export const parameters = {
|
export const parameters = {
|
||||||
@@ -7,5 +8,8 @@ export const parameters = {
|
|||||||
color: /(background|color)$/i,
|
color: /(background|color)$/i,
|
||||||
date: /Date$/
|
date: /Date$/
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
darkMode: {
|
||||||
|
dark: { ...themes.dark, appContentBg: '#0e1014', appBg: '#0e1014' }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+66
-50
@@ -28,7 +28,6 @@
|
|||||||
"add": "^2.0.6",
|
"add": "^2.0.6",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"axios-auth-refresh": "^3.3.3",
|
"axios-auth-refresh": "^3.3.3",
|
||||||
"class-variance-authority": "^0.4.0",
|
|
||||||
"classnames": "^2.3.1",
|
"classnames": "^2.3.1",
|
||||||
"cookies": "^0.8.0",
|
"cookies": "^0.8.0",
|
||||||
"cva": "npm:class-variance-authority@^0.4.0",
|
"cva": "npm:class-variance-authority@^0.4.0",
|
||||||
@@ -96,7 +95,7 @@
|
|||||||
"prettier": "^2.8.3",
|
"prettier": "^2.8.3",
|
||||||
"storybook": "^7.0.0-beta.30",
|
"storybook": "^7.0.0-beta.30",
|
||||||
"storybook-dark-mode": "^2.0.5",
|
"storybook-dark-mode": "^2.0.5",
|
||||||
"tailwindcss": "^3.1.4",
|
"tailwindcss": "3.2",
|
||||||
"typescript": "^4.9.3"
|
"typescript": "^4.9.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -9301,22 +9300,6 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/class-variance-authority": {
|
|
||||||
"version": "0.4.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/class-variance-authority/-/class-variance-authority-0.4.0.tgz",
|
|
||||||
"integrity": "sha512-74enNN8O9ZNieycac/y8FxqgyzZhZbxmCitAtAeUrLPlxjSd5zA7LfpprmxEcOmQBnaGs5hYhiSGnJ0mqrtBLQ==",
|
|
||||||
"funding": {
|
|
||||||
"url": "https://joebell.co.uk"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"typescript": ">= 4.5.5 < 5"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"typescript": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/classnames": {
|
"node_modules/classnames": {
|
||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.3.1.tgz",
|
||||||
@@ -12028,9 +12011,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/fast-glob": {
|
"node_modules/fast-glob": {
|
||||||
"version": "3.2.11",
|
"version": "3.2.12",
|
||||||
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.11.tgz",
|
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz",
|
||||||
"integrity": "sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==",
|
"integrity": "sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nodelib/fs.stat": "^2.0.2",
|
"@nodelib/fs.stat": "^2.0.2",
|
||||||
@@ -17203,12 +17186,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/postcss-nested": {
|
"node_modules/postcss-nested": {
|
||||||
"version": "5.0.6",
|
"version": "6.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/postcss-nested/-/postcss-nested-5.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/postcss-nested/-/postcss-nested-6.0.0.tgz",
|
||||||
"integrity": "sha512-rKqm2Fk0KbA8Vt3AdGN0FB9OBOMDVajMG6ZCf/GoHgdxUJ4sBFp0A/uMIRm+MJUdo33YXEtjqIz8u7DAp8B7DA==",
|
"integrity": "sha512-0DkamqrPcmkBDsLn+vQDIrtkSbNkv5AD/M322ySo9kqFkCIYklym2xEmWkwo+Y3/qZo34tzEPNUw4y7yMCdv5w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"postcss-selector-parser": "^6.0.6"
|
"postcss-selector-parser": "^6.0.10"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12.0"
|
"node": ">=12.0"
|
||||||
@@ -20420,9 +20403,9 @@
|
|||||||
"integrity": "sha512-+fflfPxvHFr81hTJpQ3MIwtqgvefHZFUHFiIHpVIRXvG/nX9+gu2P7JNlFu2bfDMJ+uHhi/pUgzaYacMoXv+Ww=="
|
"integrity": "sha512-+fflfPxvHFr81hTJpQ3MIwtqgvefHZFUHFiIHpVIRXvG/nX9+gu2P7JNlFu2bfDMJ+uHhi/pUgzaYacMoXv+Ww=="
|
||||||
},
|
},
|
||||||
"node_modules/tailwindcss": {
|
"node_modules/tailwindcss": {
|
||||||
"version": "3.1.7",
|
"version": "3.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.2.4.tgz",
|
||||||
"integrity": "sha512-r7mgumZ3k0InfVPpGWcX8X/Ut4xBfv+1O/+C73ar/m01LxGVzWvPxF/w6xIUPEztrCoz7axfx0SMdh8FH8ZvRQ==",
|
"integrity": "sha512-AhwtHCKMtR71JgeYDaswmZXhPcW9iuI9Sp2LvZPo9upDZ7231ZJ7eA9RaURbhpXGVlrjX4cFNlB4ieTetEb7hQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"arg": "^5.0.2",
|
"arg": "^5.0.2",
|
||||||
@@ -20431,18 +20414,19 @@
|
|||||||
"detective": "^5.2.1",
|
"detective": "^5.2.1",
|
||||||
"didyoumean": "^1.2.2",
|
"didyoumean": "^1.2.2",
|
||||||
"dlv": "^1.1.3",
|
"dlv": "^1.1.3",
|
||||||
"fast-glob": "^3.2.11",
|
"fast-glob": "^3.2.12",
|
||||||
"glob-parent": "^6.0.2",
|
"glob-parent": "^6.0.2",
|
||||||
"is-glob": "^4.0.3",
|
"is-glob": "^4.0.3",
|
||||||
"lilconfig": "^2.0.6",
|
"lilconfig": "^2.0.6",
|
||||||
|
"micromatch": "^4.0.5",
|
||||||
"normalize-path": "^3.0.0",
|
"normalize-path": "^3.0.0",
|
||||||
"object-hash": "^3.0.0",
|
"object-hash": "^3.0.0",
|
||||||
"picocolors": "^1.0.0",
|
"picocolors": "^1.0.0",
|
||||||
"postcss": "^8.4.14",
|
"postcss": "^8.4.18",
|
||||||
"postcss-import": "^14.1.0",
|
"postcss-import": "^14.1.0",
|
||||||
"postcss-js": "^4.0.0",
|
"postcss-js": "^4.0.0",
|
||||||
"postcss-load-config": "^3.1.4",
|
"postcss-load-config": "^3.1.4",
|
||||||
"postcss-nested": "5.0.6",
|
"postcss-nested": "6.0.0",
|
||||||
"postcss-selector-parser": "^6.0.10",
|
"postcss-selector-parser": "^6.0.10",
|
||||||
"postcss-value-parser": "^4.2.0",
|
"postcss-value-parser": "^4.2.0",
|
||||||
"quick-lru": "^5.1.1",
|
"quick-lru": "^5.1.1",
|
||||||
@@ -20459,6 +20443,30 @@
|
|||||||
"postcss": "^8.0.9"
|
"postcss": "^8.0.9"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tailwindcss/node_modules/postcss": {
|
||||||
|
"version": "8.4.21",
|
||||||
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz",
|
||||||
|
"integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==",
|
||||||
|
"dev": true,
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "opencollective",
|
||||||
|
"url": "https://opencollective.com/postcss/"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tidelift",
|
||||||
|
"url": "https://tidelift.com/funding/github/npm/postcss"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"nanoid": "^3.3.4",
|
||||||
|
"picocolors": "^1.0.0",
|
||||||
|
"source-map-js": "^1.0.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^10 || ^12 || >=14"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/tapable": {
|
"node_modules/tapable": {
|
||||||
"version": "2.2.1",
|
"version": "2.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/tapable/-/tapable-2.2.1.tgz",
|
||||||
@@ -28822,12 +28830,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"class-variance-authority": {
|
|
||||||
"version": "0.4.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/class-variance-authority/-/class-variance-authority-0.4.0.tgz",
|
|
||||||
"integrity": "sha512-74enNN8O9ZNieycac/y8FxqgyzZhZbxmCitAtAeUrLPlxjSd5zA7LfpprmxEcOmQBnaGs5hYhiSGnJ0mqrtBLQ==",
|
|
||||||
"requires": {}
|
|
||||||
},
|
|
||||||
"classnames": {
|
"classnames": {
|
||||||
"version": "2.3.1",
|
"version": "2.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.3.1.tgz",
|
||||||
@@ -30927,9 +30929,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"fast-glob": {
|
"fast-glob": {
|
||||||
"version": "3.2.11",
|
"version": "3.2.12",
|
||||||
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.11.tgz",
|
"resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.12.tgz",
|
||||||
"integrity": "sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==",
|
"integrity": "sha512-DVj4CQIYYow0BlaelwK1pHl5n5cRSJfM60UA0zK891sVInoPri2Ekj7+e1CT3/3qxXenpI+nBBmQAcJPJgaj4w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@nodelib/fs.stat": "^2.0.2",
|
"@nodelib/fs.stat": "^2.0.2",
|
||||||
@@ -34637,12 +34639,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"postcss-nested": {
|
"postcss-nested": {
|
||||||
"version": "5.0.6",
|
"version": "6.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/postcss-nested/-/postcss-nested-5.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/postcss-nested/-/postcss-nested-6.0.0.tgz",
|
||||||
"integrity": "sha512-rKqm2Fk0KbA8Vt3AdGN0FB9OBOMDVajMG6ZCf/GoHgdxUJ4sBFp0A/uMIRm+MJUdo33YXEtjqIz8u7DAp8B7DA==",
|
"integrity": "sha512-0DkamqrPcmkBDsLn+vQDIrtkSbNkv5AD/M322ySo9kqFkCIYklym2xEmWkwo+Y3/qZo34tzEPNUw4y7yMCdv5w==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"postcss-selector-parser": "^6.0.6"
|
"postcss-selector-parser": "^6.0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"postcss-selector-parser": {
|
"postcss-selector-parser": {
|
||||||
@@ -37007,9 +37009,9 @@
|
|||||||
"integrity": "sha512-+fflfPxvHFr81hTJpQ3MIwtqgvefHZFUHFiIHpVIRXvG/nX9+gu2P7JNlFu2bfDMJ+uHhi/pUgzaYacMoXv+Ww=="
|
"integrity": "sha512-+fflfPxvHFr81hTJpQ3MIwtqgvefHZFUHFiIHpVIRXvG/nX9+gu2P7JNlFu2bfDMJ+uHhi/pUgzaYacMoXv+Ww=="
|
||||||
},
|
},
|
||||||
"tailwindcss": {
|
"tailwindcss": {
|
||||||
"version": "3.1.7",
|
"version": "3.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.2.4.tgz",
|
||||||
"integrity": "sha512-r7mgumZ3k0InfVPpGWcX8X/Ut4xBfv+1O/+C73ar/m01LxGVzWvPxF/w6xIUPEztrCoz7axfx0SMdh8FH8ZvRQ==",
|
"integrity": "sha512-AhwtHCKMtR71JgeYDaswmZXhPcW9iuI9Sp2LvZPo9upDZ7231ZJ7eA9RaURbhpXGVlrjX4cFNlB4ieTetEb7hQ==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"arg": "^5.0.2",
|
"arg": "^5.0.2",
|
||||||
@@ -37018,22 +37020,36 @@
|
|||||||
"detective": "^5.2.1",
|
"detective": "^5.2.1",
|
||||||
"didyoumean": "^1.2.2",
|
"didyoumean": "^1.2.2",
|
||||||
"dlv": "^1.1.3",
|
"dlv": "^1.1.3",
|
||||||
"fast-glob": "^3.2.11",
|
"fast-glob": "^3.2.12",
|
||||||
"glob-parent": "^6.0.2",
|
"glob-parent": "^6.0.2",
|
||||||
"is-glob": "^4.0.3",
|
"is-glob": "^4.0.3",
|
||||||
"lilconfig": "^2.0.6",
|
"lilconfig": "^2.0.6",
|
||||||
|
"micromatch": "^4.0.5",
|
||||||
"normalize-path": "^3.0.0",
|
"normalize-path": "^3.0.0",
|
||||||
"object-hash": "^3.0.0",
|
"object-hash": "^3.0.0",
|
||||||
"picocolors": "^1.0.0",
|
"picocolors": "^1.0.0",
|
||||||
"postcss": "^8.4.14",
|
"postcss": "^8.4.18",
|
||||||
"postcss-import": "^14.1.0",
|
"postcss-import": "^14.1.0",
|
||||||
"postcss-js": "^4.0.0",
|
"postcss-js": "^4.0.0",
|
||||||
"postcss-load-config": "^3.1.4",
|
"postcss-load-config": "^3.1.4",
|
||||||
"postcss-nested": "5.0.6",
|
"postcss-nested": "6.0.0",
|
||||||
"postcss-selector-parser": "^6.0.10",
|
"postcss-selector-parser": "^6.0.10",
|
||||||
"postcss-value-parser": "^4.2.0",
|
"postcss-value-parser": "^4.2.0",
|
||||||
"quick-lru": "^5.1.1",
|
"quick-lru": "^5.1.1",
|
||||||
"resolve": "^1.22.1"
|
"resolve": "^1.22.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"postcss": {
|
||||||
|
"version": "8.4.21",
|
||||||
|
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.21.tgz",
|
||||||
|
"integrity": "sha512-tP7u/Sn/dVxK2NnruI4H9BG+x+Wxz6oeZ1cJ8P6G/PZY0IKk4k/63TDsQf2kQq3+qoJeLm2kIBUNlZe3zgb4Zg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"nanoid": "^3.3.4",
|
||||||
|
"picocolors": "^1.0.0",
|
||||||
|
"source-map-js": "^1.0.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tapable": {
|
"tapable": {
|
||||||
|
|||||||
@@ -102,7 +102,7 @@
|
|||||||
"prettier": "^2.8.3",
|
"prettier": "^2.8.3",
|
||||||
"storybook": "^7.0.0-beta.30",
|
"storybook": "^7.0.0-beta.30",
|
||||||
"storybook-dark-mode": "^2.0.5",
|
"storybook-dark-mode": "^2.0.5",
|
||||||
"tailwindcss": "^3.1.4",
|
"tailwindcss": "3.2",
|
||||||
"typescript": "^4.9.3"
|
"typescript": "^4.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,113 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { SelectProps } from '@radix-ui/react-select';
|
||||||
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||||
|
import { Meta, StoryObj } from '@storybook/react';
|
||||||
|
|
||||||
|
import { Select, SelectItem } from './Select';
|
||||||
|
|
||||||
|
const meta: Meta<typeof Select> = {
|
||||||
|
title: 'Components/Select',
|
||||||
|
component: Select,
|
||||||
|
tags: ['v2'],
|
||||||
|
argTypes: {
|
||||||
|
placeholder: {
|
||||||
|
defaultValue: 'Type something...'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof Select>;
|
||||||
|
|
||||||
|
export const Basic: Story = {
|
||||||
|
render: (args) => (
|
||||||
|
<div className="">
|
||||||
|
<Select placeholder="Type anything..." className="w-72" {...args}>
|
||||||
|
<SelectItem value="1">John</SelectItem>
|
||||||
|
<SelectItem value="2">Peter</SelectItem>
|
||||||
|
<SelectItem value="3">Suzy</SelectItem>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
const Controlled = (args: SelectProps) => {
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const [selected, setSelected] = useState('');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="">
|
||||||
|
<Select
|
||||||
|
defaultValue="1"
|
||||||
|
className="w-72"
|
||||||
|
open={isOpen}
|
||||||
|
onValueChange={(val) => setSelected(val)}
|
||||||
|
value={selected}
|
||||||
|
onOpenChange={(open) => setIsOpen(open)}
|
||||||
|
{...args}
|
||||||
|
>
|
||||||
|
<SelectItem value="1">John</SelectItem>
|
||||||
|
<SelectItem value="2">Peter</SelectItem>
|
||||||
|
<SelectItem value="3">Suzy</SelectItem>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Control: Story = {
|
||||||
|
render: (args) => <Controlled {...args} />
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Disabled: Story = {
|
||||||
|
render: (args) => (
|
||||||
|
<div className="">
|
||||||
|
<Select defaultValue="1" className="w-72" {...args}>
|
||||||
|
<SelectItem value="1">John</SelectItem>
|
||||||
|
<SelectItem value="2" isDisabled>
|
||||||
|
Peter
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem value="3">Suzy</SelectItem>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Loading: Story = {
|
||||||
|
render: (args) => (
|
||||||
|
<div className="">
|
||||||
|
<Select defaultValue="1" className="w-72" isLoading {...args}>
|
||||||
|
<SelectItem value="1">John</SelectItem>
|
||||||
|
<SelectItem value="2">Peter</SelectItem>
|
||||||
|
<SelectItem value="3">Suzy</SelectItem>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
const AsyncSelectOptions = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// eslint-disable-next-line no-new
|
||||||
|
new Promise<void>((resolve): void => {
|
||||||
|
setTimeout(() => {
|
||||||
|
setIsLoading(false);
|
||||||
|
resolve();
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="">
|
||||||
|
<Select placeholder="Hello" className="w-72" isLoading={isLoading}>
|
||||||
|
<SelectItem value="1">John</SelectItem>
|
||||||
|
<SelectItem value="2">Peter</SelectItem>
|
||||||
|
<SelectItem value="3">Suzy</SelectItem>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Async: Story = {
|
||||||
|
render: (args) => <AsyncSelectOptions {...args} />
|
||||||
|
};
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import { forwardRef, ReactNode } from 'react';
|
||||||
|
import { faCheck, faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
|
import * as SelectPrimitive from '@radix-ui/react-select';
|
||||||
|
import { twMerge } from 'tailwind-merge';
|
||||||
|
|
||||||
|
import { Spinner } from '../Spinner';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
children: ReactNode;
|
||||||
|
placeholder?: string;
|
||||||
|
className?: string;
|
||||||
|
isLoading?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type SelectProps = SelectPrimitive.SelectProps & Props;
|
||||||
|
|
||||||
|
export const Select = forwardRef<HTMLButtonElement, SelectProps>(
|
||||||
|
({ children, placeholder, className, isLoading, ...props }, ref): JSX.Element => {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Root {...props}>
|
||||||
|
<SelectPrimitive.Trigger
|
||||||
|
ref={ref}
|
||||||
|
className={twMerge(
|
||||||
|
`select inline-flex items-center justify-between
|
||||||
|
px-4 py-2.5 text-sm text-white rounded-md bg-mineshaft-800`,
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<SelectPrimitive.Value placeholder={placeholder} />
|
||||||
|
<SelectPrimitive.Icon className="ml-3">
|
||||||
|
<FontAwesomeIcon icon={faChevronDown} size="sm" />
|
||||||
|
</SelectPrimitive.Icon>
|
||||||
|
</SelectPrimitive.Trigger>
|
||||||
|
<SelectPrimitive.Portal>
|
||||||
|
<SelectPrimitive.Content
|
||||||
|
position="popper"
|
||||||
|
sideOffset={5}
|
||||||
|
className="overflow-hidden text-white rounded-md shadow-md bg-mineshaft-800"
|
||||||
|
style={{ width: 'var(--radix-select-trigger-width)' }}
|
||||||
|
>
|
||||||
|
<SelectPrimitive.ScrollUpButton>
|
||||||
|
<FontAwesomeIcon icon={faChevronUp} size="sm" />
|
||||||
|
</SelectPrimitive.ScrollUpButton>
|
||||||
|
<SelectPrimitive.Viewport className="p-2">
|
||||||
|
{isLoading ? (
|
||||||
|
<div className="flex items-center justify-center">
|
||||||
|
<Spinner size="xs" />
|
||||||
|
<span className="ml-2 text-xs text-gray-500">Loading...</span>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
children
|
||||||
|
)}
|
||||||
|
</SelectPrimitive.Viewport>
|
||||||
|
<SelectPrimitive.ScrollDownButton>
|
||||||
|
<FontAwesomeIcon icon={faChevronDown} size="sm" />
|
||||||
|
</SelectPrimitive.ScrollDownButton>
|
||||||
|
</SelectPrimitive.Content>
|
||||||
|
</SelectPrimitive.Portal>
|
||||||
|
</SelectPrimitive.Root>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
Select.displayName = 'Select';
|
||||||
|
|
||||||
|
type SelectItemProps = Omit<SelectPrimitive.SelectItemProps, 'disabled'> & {
|
||||||
|
isDisabled?: boolean;
|
||||||
|
isSelected?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SelectItem = forwardRef<HTMLDivElement, SelectItemProps>(
|
||||||
|
({ children, className, isSelected, isDisabled, ...props }, forwardedRef) => {
|
||||||
|
return (
|
||||||
|
<SelectPrimitive.Item
|
||||||
|
{...props}
|
||||||
|
className={twMerge(
|
||||||
|
`text-sm rounded-sm transition-all hover:text-primary
|
||||||
|
hover:bg-mineshaft-700 flex items-center pl-10 pr-4 py-2 cursor-pointer
|
||||||
|
select-none outline-none relative`,
|
||||||
|
isSelected && 'text-primary',
|
||||||
|
isDisabled && 'text-gray-600 hover:bg-transparent cursor-not-allowed hover:text-gray-600',
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
ref={forwardedRef}
|
||||||
|
>
|
||||||
|
<SelectPrimitive.ItemIndicator className="absolute left-2">
|
||||||
|
<FontAwesomeIcon icon={faCheck} size="sm" />
|
||||||
|
</SelectPrimitive.ItemIndicator>
|
||||||
|
<SelectPrimitive.ItemText className="">{children}</SelectPrimitive.ItemText>
|
||||||
|
</SelectPrimitive.Item>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
SelectItem.displayName = 'SelectItem';
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export {Select} from './Select'
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { twMerge } from 'tailwind-merge';
|
||||||
|
|
||||||
|
type SizeOptions = 'xs' | 'sm' | 'md' | 'lg';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
className?: string;
|
||||||
|
size?: SizeOptions;
|
||||||
|
};
|
||||||
|
|
||||||
|
const sizeChart: Record<SizeOptions, string> = {
|
||||||
|
xs: 'w-4 h-4',
|
||||||
|
sm: 'w-6 h-6',
|
||||||
|
md: 'w-8 h-8',
|
||||||
|
lg: 'w-12 h-12'
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Spinner = ({ className, size = 'md' }: Props): JSX.Element => {
|
||||||
|
return (
|
||||||
|
<div role="status">
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
className={twMerge(
|
||||||
|
' text-gray-200 animate-spin dark:text-gray-600 fill-primary m-1',
|
||||||
|
sizeChart[size],
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
viewBox="0 0 100 101"
|
||||||
|
fill="none"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||||
|
fill="currentFill"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
export { Spinner } from './Spinner';
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
@tailwind base;
|
@tailwind base;
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
|
@layer components {
|
||||||
|
.select[data-placeholder] {
|
||||||
|
color: theme("colors.gray.500")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user