The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
chore(studio): consistent copy/reveal input behaviour (#39509)
Danny White73f8a1520339
diff --git a/apps/design-system/README.md b/apps/design-system/README.mdindex 96a8eaf8fef..12706027761 100644--- a/apps/design-system/README.md+++ b/apps/design-system/README.md@@ -47,3 +47,26 @@ Open [http://localhost:3003](http://localhost:3003) in your browser to see the r### Watching for MDX changesThe `dev:full` command automatically watches for changes to MDX files with hot reload. If you're running the `pnpm dev` separately, you'll need to run `pnpm content:dev` in a separate terminal shell to watch for content changes.++### Adding components++The design system _references_ components rather than housing them. That’s an important distinction to make, as everything that follows here is about the documentation of components. You can add or edit components in one of these two places:++- [`packages/ui`](https://github.com/supabase/supabase/tree/master/packages/ui): basic UI components+- [`packages/ui-patterns`](https://github.com/supabase/supabase/tree/master/packages/ui-patterns): components which are built using NPM libraries or amalgamations of components from `patterns/ui`++With that out of the way, there are several parts of this design system that need to be manually updated after components have been added or removed (from documentation). These include:++- `config/docs.ts`: list of components in the sidebar+- `content/docs`: where the actual component documentation `.mdx` file lives+- `registry/examples.ts`: list of example components+- `registry/default/example`: where the actual example component(s) live+- `registry/charts.ts`: Chart components+- `registry/fragments.ts`: Fragment components++You will need to rebuild the design system’s registry each time a new example component is added. In other words: whenever a new file enters `registry`, it needs to be rebuilt. You can do that via:++```bash+cd apps/design-system+pnpm build:registry+```diff --git a/apps/design-system/__registry__/index.tsx b/apps/design-system/__registry__/index.tsxindex 912c60fe77c..005d8278801 100644--- a/apps/design-system/__registry__/index.tsx+++ b/apps/design-system/__registry__/index.tsx@@ -588,6 +588,50 @@ export const Index: Record<string, any> = {subcategory: "undefined",chunks: []},+ "data-input-demo": {+ name: "data-input-demo",+ type: "components:example",+ registryDependencies: ["data-input"],+ component: React.lazy(() => import("@/registry/default/example/data-input-demo")),+ source: "",+ files: ["registry/default/example/data-input-demo.tsx"],+ category: "undefined",+ subcategory: "undefined",+ chunks: []+ },+ "data-input-with-copy": {+ name: "data-input-with-copy",+ type: "components:example",+ registryDependencies: ["data-input"],+ component: React.lazy(() => import("@/registry/default/example/data-input-with-copy")),+ source: "",+ files: ["registry/default/example/data-input-with-copy.tsx"],+ category: "undefined",+ subcategory: "undefined",+ chunks: []+ },+ "data-input-with-copy-secret": {+ name: "data-input-with-copy-secret",+ type: "components:example",+ registryDependencies: ["data-input"],+ component: React.lazy(() => import("@/registry/default/example/data-input-with-copy-secret")),+ source: "",+ files: ["registry/default/example/data-input-with-copy-secret.tsx"],+ category: "undefined",+ subcategory: "undefined",+ chunks: []+ },+ "data-input-with-reveal-copy": {+ name: "data-input-with-reveal-copy",+ type: "components:example",+ registryDependencies: ["data-input"],+ component: React.lazy(() => import("@/registry/default/example/data-input-with-reveal-copy")),+ source: "",+ files: ["registry/default/example/data-input-with-reveal-copy.tsx"],+ category: "undefined",+ subcategory: "undefined",+ chunks: []+ },"date-picker-demo": {name: "date-picker-demo",type: "components:example",diff --git a/apps/design-system/config/docs.ts b/apps/design-system/config/docs.tsindex c41034a9f2f..35407e0b433 100644--- a/apps/design-system/config/docs.ts+++ b/apps/design-system/config/docs.ts@@ -117,6 +117,11 @@ export const docsConfig: DocsConfig = {href: '/docs/fragments/inner-side-menu',items: [],},+ {+ title: 'Data Input',+ href: '/docs/fragments/data-input',+ items: [],+ },{title: 'Form Item Layout',href: '/docs/fragments/form-item-layout',diff --git a/apps/design-system/content/docs/fragments/data-input.mdx b/apps/design-system/content/docs/fragments/data-input.mdxnew file mode 100644index 00000000000..040c3e9dcc5--- /dev/null+++ b/apps/design-system/content/docs/fragments/data-input.mdx@@ -0,0 +1,47 @@+---+title: Data Input+description: Set, read, or copy a value on a single line.+component: true+---++<ComponentPreview name="data-input-demo" peekCode wide />++Referred to as `Input` in code, not `DataInput`. Also not to be confused with the atomic [Input](../components/input) component.++## Usage++### Read-only values++Input should be used for read-only values that can be copied or otherwise interacted with, as the input element is both keyboard and mouse-friendly.++<ComponentPreview name="data-input-with-copy" peekCode wide />++### Sensitive values++Inputs with sensitive values can be both revealed _and_ copied, but only in succession. This reduces the amount of actions on screen, thus simplifying the interface.++<ComponentPreview name="data-input-with-reveal-copy" peekCode wide />++You can also partially truncate the value by overriding the placeholder value.++Consider if the value needs to be revealed in the first place, as only copying is sufficient in most cases.++A happy medium might be to display a partially masked value but saving the actual value in the clipboard. To do this, pass a pre-masked string as the `value` prop and override the `onCopy` callback to copy the real value.++<ComponentPreview name="data-input-with-copy-secret" peekCode wide />++### Password managers++In some cases, you may need to add the following attribute to your input to prevent password managers from applying their widgets and dropdowns to the input:++```jsx+<Input+ readOnly+ copy+ value={name}+ data-1p-ignore // 1Password+ data-lpignore="true" // LastPass+ data-form-type="other" // Dashlane+ data-bwignore // Bitwarden+/>+```diff --git a/apps/design-system/registry/default/example/data-input-demo.tsx b/apps/design-system/registry/default/example/data-input-demo.tsxnew file mode 100644index 00000000000..c31326de17f--- /dev/null+++ b/apps/design-system/registry/default/example/data-input-demo.tsx@@ -0,0 +1,5 @@+import { Input } from 'ui-patterns/DataInputs/Input'++export default function DataInputDemo() {+ return <Input containerClassName="w-full max-w-sm" placeholder="Hello world" />+}diff --git a/apps/design-system/registry/default/example/data-input-with-copy-secret.tsx b/apps/design-system/registry/default/example/data-input-with-copy-secret.tsxnew file mode 100644index 00000000000..f09531f6a25--- /dev/null+++ b/apps/design-system/registry/default/example/data-input-with-copy-secret.tsx@@ -0,0 +1,18 @@+import { Input } from 'ui-patterns/DataInputs/Input'++export default function DataInputWithCopySecret() {+ const actualValue = 'sb_secret_1234567890'+ const maskedValue = 'sb_secret_123•••••••'++ return (+ <Input+ containerClassName="w-full max-w-sm"+ readOnly+ copy+ value={maskedValue}+ onCopy={() => {+ navigator.clipboard.writeText(actualValue)+ }}+ />+ )+}diff --git a/apps/design-system/registry/default/example/data-input-with-copy.tsx b/apps/design-system/registry/default/example/data-input-with-copy.tsxnew file mode 100644index 00000000000..52a3cc7bd76--- /dev/null+++ b/apps/design-system/registry/default/example/data-input-with-copy.tsx@@ -0,0 +1,5 @@+import { Input } from 'ui-patterns/DataInputs/Input'++export default function DataInputWithCopy() {+ return <Input containerClassName="w-full max-w-sm" readOnly copy value="1234567890" />+}diff --git a/apps/design-system/registry/default/example/data-input-with-reveal-copy.tsx b/apps/design-system/registry/default/example/data-input-with-reveal-copy.tsxnew file mode 100644index 00000000000..168a155961c--- /dev/null+++ b/apps/design-system/registry/default/example/data-input-with-reveal-copy.tsx@@ -0,0 +1,5 @@+import { Input } from 'ui-patterns/DataInputs/Input'++export default function DataInputWithRevealCopy() {+ return <Input containerClassName="w-full max-w-sm" readOnly reveal copy value="1234567890" />+}diff --git a/apps/design-system/registry/examples.ts b/apps/design-system/registry/examples.tsindex 4e389b1d238..b47de24fed5 100644--- a/apps/design-system/registry/examples.ts+++ b/apps/design-system/registry/examples.ts@@ -385,12 +385,30 @@ export const examples: Registry = [registryDependencies: ['context-menu'],files: ['example/context-menu-demo.tsx'],},- // {- // name: 'data-table-demo',- // type: 'components:example',- // registryDependencies: ['data-table'],- // files: ['example/data-table-demo.tsx'],- // },+ {+ name: 'data-input-demo',+ type: 'components:example',+ registryDependencies: ['data-input'],+ files: ['example/data-input-demo.tsx'],+ },+ {+ name: 'data-input-with-copy',+ type: 'components:example',+ registryDependencies: ['data-input'],+ files: ['example/data-input-with-copy.tsx'],+ },+ {+ name: 'data-input-with-copy-secret',+ type: 'components:example',+ registryDependencies: ['data-input'],+ files: ['example/data-input-with-copy-secret.tsx'],+ },+ {+ name: 'data-input-with-reveal-copy',+ type: 'components:example',+ registryDependencies: ['data-input'],+ files: ['example/data-input-with-reveal-copy.tsx'],+ },{name: 'date-picker-demo',type: 'components:example',diff --git a/apps/studio/components/interfaces/Settings/API/ServiceList.tsx b/apps/studio/components/interfaces/Settings/API/ServiceList.tsxindex 2b16008778b..763bb0cee07 100644--- a/apps/studio/components/interfaces/Settings/API/ServiceList.tsx+++ b/apps/studio/components/interfaces/Settings/API/ServiceList.tsx@@ -95,7 +95,7 @@ export const ServiceList = () => {: 'RESTful endpoint for querying and managing your database'}>- <Input copy readOnly disabled className="input-mono" value={endpoint} />+ <Input copy readOnly className="font-mono" value={endpoint} /></FormLayout>)}</CardContent>diff --git a/apps/studio/components/interfaces/Storage/StorageSettings/S3Connection.tsx b/apps/studio/components/interfaces/Storage/StorageSettings/S3Connection.tsxindex 9a1d087728c..3911ec4150c 100644--- a/apps/studio/components/interfaces/Storage/StorageSettings/S3Connection.tsx+++ b/apps/studio/components/interfaces/Storage/StorageSettings/S3Connection.tsx@@ -172,11 +172,19 @@ export const S3Connection = () => {<CardContent className="py-6"><div className="flex flex-col gap-y-4"><FormItemLayout layout="horizontal" label="Endpoint" isReactForm={false}>- <Input readOnly copy disabled value={s3connectionUrl} />+ <Input readOnly copy value={s3connectionUrl} /></FormItemLayout>{!projectIsLoading && (<FormItemLayout layout="horizontal" label="Region" isReactForm={false}>- <Input className="input-mono" copy disabled value={project?.region} />+ <Input+ readOnly+ copy+ value={project?.region}+ data-1p-ignore+ data-lpignore="true"+ data-form-type="other"+ data-bwignore+ /></FormItemLayout>)}</div>diff --git a/apps/studio/components/interfaces/Storage/StorageSettings/StorageCredItem.tsx b/apps/studio/components/interfaces/Storage/StorageSettings/StorageCredItem.tsxindex 043780f89be..fb24091c0c5 100644--- a/apps/studio/components/interfaces/Storage/StorageSettings/StorageCredItem.tsx+++ b/apps/studio/components/interfaces/Storage/StorageSettings/StorageCredItem.tsx@@ -1,9 +1,7 @@import { PermissionAction } from '@supabase/shared-types/out/constants'import { differenceInDays } from 'date-fns'-import { MoreVertical, TrashIcon } from 'lucide-react'--import CopyButton from 'components/ui/CopyButton'import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'+import { MoreVertical, TrashIcon } from 'lucide-react'import {Button,DropdownMenu,@@ -13,6 +11,7 @@ import {TableCell,TableRow,} from 'ui'+import { Input } from 'ui-patterns/DataInputs/Input'export const StorageCredItem = ({description,@@ -52,12 +51,7 @@ export const StorageCredItem = ({<span className="text-foreground">{description}</span></TableCell><TableCell>- <div className="flex items-center justify-between">- <span className="text-ellipsis font-mono cursor-default">{access_key}</span>- <span className="w-24 text-right opacity-0 group-hover:opacity-100 transition-opacity">- <CopyButton text={access_key} type="default" />- </span>- </div>+ <Input readOnly copy value={access_key} className="font-mono" /></TableCell><TableCell className="text-foreground-lighter">{daysSince(created_at)}</TableCell><TableCell className="text-right">diff --git a/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx b/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsxindex 80277032385..71f99c36a12 100644--- a/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx+++ b/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx@@ -10,7 +10,8 @@ import Panel from 'components/ui/Panel'import { useJwtSecretUpdatingStatusQuery } from 'data/config/jwt-secret-updating-status-query'import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'-import { Input } from 'ui'+import { Input } from 'ui-patterns/DataInputs/Input'+import { FormLayout } from 'ui-patterns/form/Layout/FormLayout'import { getLastUsedAPIKeys, useLastUsedAPIKeysLogQuery } from './DisplayApiSettings.utils'export const DisplayApiSettings = ({@@ -123,12 +124,8 @@ export const DisplayApiSettings = ({'border-t border-panel-border-interior-light [[data-theme*=dark]_&]:border-panel-border-interior-dark'}>- <Input- readOnly- disabled+ <FormLayoutlayout="horizontal"- className="input-mono"- // @ts-ignorelabel={<>{x.tags?.split(',').map((x, i: number) => (@@ -146,19 +143,7 @@ export const DisplayApiSettings = ({{x.tags === 'anon' && <code className="text-xs text-code">public</code>}</>}- copy={canReadAPIKeys && isNotUpdatingJwtSecret}- reveal={x.tags !== 'anon' && canReadAPIKeys && isNotUpdatingJwtSecret}- value={- !canReadAPIKeys- ? 'You need additional permissions to view API keys'- : jwtSecretUpdateStatus === JwtSecretUpdateStatus.Failed- ? 'JWT secret update failed, new API key may have issues'- : jwtSecretUpdateStatus === JwtSecretUpdateStatus.Updating- ? 'Updating JWT secret...'- : x?.api_key ?? 'You need additional permissions to view API keys'- }- onChange={() => {}}- descriptionText={+ description={x.tags === 'service_role' ? (<>This key has the ability to bypass Row Level Security. Never share it publicly.@@ -195,7 +180,24 @@ export const DisplayApiSettings = ({</>)}- />+ >+ <Input+ readOnly+ className="font-mono"+ copy={canReadAPIKeys && isNotUpdatingJwtSecret}+ reveal={x.tags !== 'anon' && canReadAPIKeys && isNotUpdatingJwtSecret}+ value={+ !canReadAPIKeys+ ? 'You need additional permissions to view API keys'+ : jwtSecretUpdateStatus === JwtSecretUpdateStatus.Failed+ ? 'JWT secret update failed, new API key may have issues'+ : jwtSecretUpdateStatus === JwtSecretUpdateStatus.Updating+ ? 'Updating JWT secret...'+ : x?.api_key ?? 'You need additional permissions to view API keys'+ }+ onChange={() => {}}+ />+ </FormLayout><divclassName="pt-2 text-foreground-lighter w-full text-sm data-[invisible=true]:invisible"diff --git a/packages/ui-patterns/src/DataInputs/Input.tsx b/packages/ui-patterns/src/DataInputs/Input.tsxindex 6a22820be61..36094a03a24 100644--- a/packages/ui-patterns/src/DataInputs/Input.tsx+++ b/packages/ui-patterns/src/DataInputs/Input.tsx@@ -71,12 +71,12 @@ const Input = forwardRef<{...props}onCopy={onCopy}value={reveal && hidden ? HIDDEN_PLACEHOLDER : props.value}+ disabled={reveal && hidden ? true : props.disabled}className={cn(...inputClasses, props.className)}/>{icon && <InputIconContainer icon={icon} className={iconContainerClassName} />}{copy || actions ? (<div className={__styles.actions_container}>- {/* {error && <InputErrorIcon size={size} />} */}{copy && !(reveal && hidden) ? (<Buttonsize="tiny"@@ -102,173 +102,3 @@ const Input = forwardRef<)export { Input }--// export interface TextAreaProps-// extends Omit<React.InputHTMLAttributes<HTMLTextAreaElement>, 'size' | 'onCopy'> {-// textAreaClassName?: string-// descriptionText?: string | React.ReactNode | undefined-// error?: string-// icon?: any-// label?: string | React.ReactNode-// afterLabel?: string-// beforeLabel?: string-// labelOptional?: string | React.ReactNode-// layout?: 'horizontal' | 'vertical'-// rows?: number-// limit?: number-// size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge'-// borderless?: boolean-// validation?: (x: any) => void-// copy?: boolean-// onCopy?: () => void-// actions?: React.ReactNode-// }--// function TextArea({-// className,-// textAreaClassName,-// descriptionText,-// disabled,-// error,-// icon,-// id = '',-// name = '',-// label,-// afterLabel,-// beforeLabel,-// labelOptional,-// layout,-// onChange,-// onBlur,-// placeholder,-// value,-// style,-// rows = 4,-// limit,-// size,-// borderless = false,-// validation,-// copy = false,-// onCopy,-// actions,-// ...props-// }: TextAreaProps) {-// const [charLength, setCharLength] = useState(0)-// const [copyLabel, setCopyLabel] = useState('Copy')--// function _onCopy(value: any) {-// navigator.clipboard.writeText(value).then(-// function () {-// /* clipboard successfully set */-// setCopyLabel('Copied')-// setTimeout(function () {-// setCopyLabel('Copy')-// }, 3000)-// onCopy?.()-// },-// function () {-// /* clipboard write failed */-// setCopyLabel('Failed to copy')-// }-// )-// }--// const { formContextOnChange, values, errors, handleBlur, touched, fieldLevelValidation } =-// useFormContext()--// if (values && !value) value = values[id || name]--// function handleBlurEvent(e: React.FocusEvent<HTMLTextAreaElement>) {-// if (handleBlur) {-// setTimeout(() => {-// handleBlur(e)-// }, 100)-// }-// if (onBlur) onBlur(e)-// }--// if (!error) {-// if (errors && !error) error = errors[id || name]-// error = touched && touched[id || name] ? error : undefined-// }--// function onInputChange(e: React.ChangeEvent<HTMLTextAreaElement>) {-// setCharLength(e.target.value.length)-// if (onChange) onChange(e)-// // update form-// if (formContextOnChange) formContextOnChange(e)-// // run field level validation-// if (validation) fieldLevelValidation(id, validation(e.target.value))-// }--// useEffect(() => {-// if (validation) fieldLevelValidation(id, validation(value))-// }, [])--// const __styles = styleHandler('input')--// let classes = [__styles.base]--// if (error) classes.push(__styles.variants.error)-// if (!error) classes.push(__styles.variants.standard)-// if (icon) classes.push(__styles.with_icon)-// if (size) classes.push(__styles.size[size])-// if (disabled) classes.push(__styles.disabled)-// if (textAreaClassName) classes.push(textAreaClassName)--// return (-// <FormLayout-// className={className}-// label={label}-// afterLabel={afterLabel}-// beforeLabel={beforeLabel}-// labelOptional={labelOptional}-// layout={layout}-// id={id}-// error={error}-// descriptionText={descriptionText}-// style={style}-// size={size}-// >-// <div className={__styles.container}>-// <textarea-// disabled={disabled}-// id={id}-// name={name}-// rows={rows}-// cols={100}-// placeholder={placeholder}-// onChange={onInputChange}-// onBlur={handleBlurEvent}-// onCopy={onCopy}-// value={value}-// className={classes.join(' ')}-// maxLength={limit}-// {...props}-// />-// {copy || error || actions ? (-// <div className={__styles['textarea_actions_container']}>-// <div className={__styles['textarea_actions_container_items']}>-// {error && <InputErrorIcon size={size} />}-// {copy && (-// <Button-// size="tiny"-// type="default"-// onClick={() => _onCopy(value)}-// icon={<IconCopy />}-// >-// {copyLabel}-// </Button>-// )}-// {actions && actions}-// </div>-// </div>-// ) : null}-// </div>-// </FormLayout>-// )-// }--// Input.TextArea = TextArea--// export default Inputdiff --git a/packages/ui/src/components/shadcn/ui/input.tsx b/packages/ui/src/components/shadcn/ui/input.tsxindex 6b109a2a985..880315d0f17 100644--- a/packages/ui/src/components/shadcn/ui/input.tsx+++ b/packages/ui/src/components/shadcn/ui/input.tsx@@ -9,8 +9,8 @@ export interface InputPropsexport const InputVariants = cva(cn(- 'flex h-10 w-full rounded-md border border-control bg-foreground/[.026] px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-foreground-muted',- 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-background-control focus-visible:ring-offset-2 focus-visible:ring-offset-foreground-muted disabled:cursor-not-allowed disabled:opacity-50',+ 'flex h-10 w-full rounded-md border border-control read-only:border-button bg-foreground/[.026] px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-foreground-muted read-only:text-foreground-light',+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-background-control focus-visible:ring-offset-2 focus-visible:ring-offset-foreground-muted disabled:cursor-not-allowed disabled:text-foreground-muted','aria-[] aria-[invalid=true]:bg-destructive-200 aria-[invalid=true]:border-destructive-400 aria-[invalid=true]:focus:border-destructive aria-[invalid=true]:focus-visible:border-destructive'),{