Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion r/accordion.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/badge.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/button-group.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/button.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/calendar.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/card.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/checkbox.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/code-editor.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions r/color-picker.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/combobox.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/command.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/date-picker.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/date-range-picker.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/documentation-link.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/empty.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/input-group.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/input-otp.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions r/input.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/item.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/label.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/multi-select.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/popover.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/progress.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/radio-group.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion r/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -1597,7 +1597,8 @@
"registryDependencies": [
"@cipher/cipher-base",
"@cipher/icon",
"@cipher/kbd"
"@cipher/kbd",
"@cipher/tooltip"
],
"files": [
{
Expand Down
2 changes: 1 addition & 1 deletion r/secret-input.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/secret-path-input.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/select.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/separator.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/session-replay.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/skeleton.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/slider.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/switch.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/tabs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/tags-input.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/textarea.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/toggle-group.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/toggle.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion r/tooltip.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions site/src/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,10 @@
{
"title": "Suggested value",
"module": "input/suggested-value"
},
{
"title": "Disabled with a reason, beside read only",
"module": "input/disabled-reason"
}
]
},
Expand Down
28 changes: 28 additions & 0 deletions site/src/examples/input/disabled-reason.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Field } from "@infisical/cipher/ui/field";
import { Input } from "@infisical/cipher/ui/input";

const REASON = "The name is shared across environments. Rename it from the secret's row.";

export default function Example() {
return (
<div className="grid w-full min-w-0 grid-cols-[repeat(auto-fit,minmax(min(100%,15rem),1fr))] items-start gap-x-6 gap-y-8">
<Field label="Editable">
<Input mono defaultValue="DATABASE_URL" />
</Field>
<Field label="Read only">
<Input mono readOnly defaultValue="DATABASE_URL" />
</Field>
<Field label="Disabled with a reason">
<Input mono defaultValue="DATABASE_URL" disabledReason={REASON} />
</Field>
<Field label="Read only with a reason">
<Input
mono
readOnly
defaultValue="STRIPE_SECRET_KEY_FOR_THE_PAYMENTS_LEDGER_REPLICA"
disabledReason={REASON}
/>
</Field>
</div>
);
}
4 changes: 3 additions & 1 deletion src/ui/color-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ export function ColorPicker({
presets,
disabled,
readOnly,
disabledReason,
placeholder = "#000000",
...props
}: ColorPickerProps) {
const [open, setOpen] = React.useState(false);
const locked = Boolean(disabled || readOnly);
const locked = Boolean(disabled || readOnly || disabledReason);
const preset = presets?.find((entry) => entry.value.toLowerCase() === value.toLowerCase());
const swatch = (
<span
Expand All @@ -69,6 +70,7 @@ export function ColorPicker({
placeholder={placeholder}
disabled={disabled}
readOnly={readOnly}
disabledReason={disabledReason}
onChange={(event) => onChange(event.target.value)}
trailing={
presets?.length ? (
Expand Down
4 changes: 2 additions & 2 deletions src/ui/controls.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
color: var(--cipher-muted);
}
@media (hover: hover) {
.field:hover:not(:disabled, [aria-disabled="true"]) {
.field:hover:not(:disabled, [aria-disabled="true"], [data-control-disabled]) {
background-color: var(--cipher-control-surface-hover);
}
}
Expand All @@ -98,7 +98,7 @@
cursor: not-allowed;
opacity: 0.5;
}
.field:is([readonly], [data-field-box][data-control-readonly]) {
.field:is([readonly]:not([aria-disabled="true"]), [data-field-box][data-control-readonly]) {
Comment thread
capy-ai[bot] marked this conversation as resolved.
Resolved
background-color: var(--cipher-paper);
}
.fieldBox {
Expand Down
45 changes: 38 additions & 7 deletions src/ui/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useSlashShortcut } from "../lib/slash-shortcut";
import { cn } from "../lib/utils";
import { Icon, type IconSource } from "./icon";
import { Kbd } from "./kbd";
import { Tooltip, TooltipProvider } from "./tooltip";

import styles from "./controls.module.css";

Expand All @@ -16,11 +17,11 @@ export const fieldBoxFlags = {
"data-control-invalid": `:is([data-field-control], ${field})[aria-invalid="true"]`,
"data-control-input-focus": "[data-field-control]:focus-visible",
"data-control-invalid-focus": `[data-field-control][aria-invalid="true"]:focus-visible, ${field}[aria-invalid="true"]:is(:focus-visible, [aria-expanded="true"])`,
"data-control-disabled": "[data-field-control]:disabled",
"data-control-readonly": "[data-field-control][readonly]"
"data-control-disabled": '[data-field-control]:is(:disabled, [aria-disabled="true"])',
"data-control-readonly": '[data-field-control][readonly]:not([aria-disabled="true"])'
};
export const fieldBoxWatch = {
attributes: ["aria-invalid", "aria-expanded", "disabled", "readonly"],
attributes: ["aria-invalid", "aria-expanded", "aria-disabled", "disabled", "readonly"],
focus: true
};

Expand All @@ -39,6 +40,8 @@ export type InputProps = Omit<React.ComponentPropsWithoutRef<"input">, "size" |
slashShortcut?: boolean;
/** Shown as the placeholder. While the field is empty, Tab or the Tab key cap fills it in, such as a generated name. */
suggestedValue?: string;
/** Blocks editing and says why: the field looks disabled but stays focusable and selectable, shows the reason in a tooltip on hover and focus, and exposes it as the accessible description. It replaces readOnly's lock. */
disabledReason?: string;
Comment thread
capy-ai[bot] marked this conversation as resolved.
Resolved
};
export function Input({
className,
Expand All @@ -52,8 +55,10 @@ export function Input({
width,
slashShortcut = false,
suggestedValue,
disabledReason,
placeholder,
onKeyDown,
onClick,
ref,
...props
}: InputProps & { ref?: React.Ref<HTMLInputElement> }) {
Expand All @@ -68,7 +73,9 @@ export function Input({
}
});
const hintId = React.useId();
const suggesting = Boolean(suggestedValue) && !props.readOnly && !props.disabled;
const reasonId = React.useId();
const reason = disabledReason || undefined;
const suggesting = Boolean(suggestedValue) && !props.readOnly && !props.disabled && !reason;
const accept = () => {
const element = inner.current;
if (!element || !suggestedValue || element.value) return;
Expand All @@ -79,7 +86,7 @@ export function Input({
element.dispatchEvent(new Event("input", { bubbles: true }));
};
const fieldSize = typeof size === "number" ? "sm" : size;
const leading = icon ?? (props.readOnly ? "lock" : undefined);
const leading = icon ?? (props.readOnly && !reason ? "lock" : undefined);
const trailed = Boolean(kbd || trailing || suggesting);
const boxed = Boolean(leading || kbd || trailing || suggestedValue);
const boxRef = useDescendantFlags<HTMLSpanElement>(fieldBoxFlags, fieldBoxWatch);
Expand All @@ -101,10 +108,19 @@ export function Input({
placeholder={suggestedValue || placeholder}
{...props}
{...field}
disabled={reason ? undefined : props.disabled}
readOnly={reason ? true : props.readOnly}
aria-disabled={reason ? true : props["aria-disabled"]}
Comment thread
capy-ai[bot] marked this conversation as resolved.
Resolved
Comment thread
capy-ai[bot] marked this conversation as resolved.
Resolved
aria-invalid={invalid || field["aria-invalid"] || undefined}
aria-describedby={
[field["aria-describedby"], suggesting && hintId].filter(Boolean).join(" ") || undefined
[field["aria-describedby"], suggesting && hintId, reason && reasonId]
.filter(Boolean)
.join(" ") || undefined
}
onClick={(event) => {
onClick?.(event);
if (reason) event.preventDefault();
}}
onKeyDown={(event) => {
onKeyDown?.(event);
if (
Expand All @@ -120,7 +136,7 @@ export function Input({
}}
/>
);
return boxed ? (
const control = boxed ? (
<span
ref={boxRef}
className={cn(styles.field, styles.fieldBox)}
Expand Down Expand Up @@ -170,5 +186,20 @@ export function Input({
) : (
input
);
return (
<>
{/* The tooltip always renders, closed and blank without a reason, so adding or removing one keeps the same input and its typed value. Its own provider keeps that from requiring one around every Input. */}
<TooltipProvider>
<Tooltip content={reason || " "} open={reason ? undefined : false} defaultOpen={false}>
{control}
</Tooltip>
</TooltipProvider>
{reason && (
<span id={reasonId} className="sr-only">
{reason}
</span>
)}
</>
);
}
Input.displayName = "Input";
5 changes: 4 additions & 1 deletion src/ui/secret-path-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function SecretPathInput({
mono = true,
disabled,
readOnly,
disabledReason,
onFocus,
onBlur,
onKeyDown,
Expand Down Expand Up @@ -94,7 +95,8 @@ export function SecretPathInput({
)
: [];
const suggestions = [...folderSuggestions, ...globRows];
const open = focused && !dismissed && !disabled && !readOnly && suggestions.length > 0;
const open =
focused && !dismissed && !disabled && !readOnly && !disabledReason && suggestions.length > 0;
const current = open && active < suggestions.length ? active : -1;

React.useEffect(() => {
Expand Down Expand Up @@ -129,6 +131,7 @@ export function SecretPathInput({
mono={mono}
disabled={disabled}
readOnly={readOnly}
disabledReason={disabledReason}
autoComplete="off"
spellCheck={false}
aria-autocomplete="list"
Expand Down
Loading