@ciridae/ui 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -151,6 +151,14 @@ export declare const englishLabels: {
|
|
|
151
151
|
clearFilters: string;
|
|
152
152
|
unavailable: string;
|
|
153
153
|
};
|
|
154
|
+
profileDialog: {
|
|
155
|
+
title: string;
|
|
156
|
+
name: string;
|
|
157
|
+
saveName: string;
|
|
158
|
+
changePicture: string;
|
|
159
|
+
nameFailed: string;
|
|
160
|
+
pictureFailed: string;
|
|
161
|
+
};
|
|
154
162
|
activity: {
|
|
155
163
|
show: string;
|
|
156
164
|
all: string;
|
|
@@ -124,6 +124,14 @@ export const englishLabels = {
|
|
|
124
124
|
clearFilters: "Clear filters",
|
|
125
125
|
unavailable: "Could not load members",
|
|
126
126
|
},
|
|
127
|
+
profileDialog: {
|
|
128
|
+
title: "Profile",
|
|
129
|
+
name: "Name",
|
|
130
|
+
saveName: "Save name",
|
|
131
|
+
changePicture: "Change picture",
|
|
132
|
+
nameFailed: "Name was not saved.",
|
|
133
|
+
pictureFailed: "Picture was not saved.",
|
|
134
|
+
},
|
|
127
135
|
activity: {
|
|
128
136
|
show: "Show",
|
|
129
137
|
all: "All",
|
|
@@ -493,6 +501,7 @@ function mergeLabels(overrides) {
|
|
|
493
501
|
dropzone: { ...englishLabels.dropzone, ...overrides.dropzone },
|
|
494
502
|
userChip: { ...englishLabels.userChip, ...overrides.userChip },
|
|
495
503
|
memberDirectory: { ...englishLabels.memberDirectory, ...overrides.memberDirectory },
|
|
504
|
+
profileDialog: { ...englishLabels.profileDialog, ...overrides.profileDialog },
|
|
496
505
|
activity: { ...englishLabels.activity, ...overrides.activity },
|
|
497
506
|
notifications: { ...englishLabels.notifications, ...overrides.notifications },
|
|
498
507
|
feedback: { ...englishLabels.feedback, ...overrides.feedback },
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ComponentProps } from "react";
|
|
2
|
+
import { Dialog } from "./overlays.js";
|
|
3
|
+
export type ProfileDialogProps = Pick<ComponentProps<typeof Dialog>, "trigger" | "open" | "onOpenChange"> & {
|
|
4
|
+
name: string | null;
|
|
5
|
+
email: string | null;
|
|
6
|
+
pictureUrl: string | null;
|
|
7
|
+
onSaveName: (name: string) => Promise<unknown>;
|
|
8
|
+
onSavePicture: (picture: File) => Promise<unknown>;
|
|
9
|
+
};
|
|
10
|
+
export declare function ProfileDialog({ name, email, pictureUrl, onSaveName, onSavePicture, onOpenChange, ...dialogProps }: ProfileDialogProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { PlusIcon } from "@phosphor-icons/react";
|
|
3
|
+
import { useMutation } from "@tanstack/react-query";
|
|
4
|
+
import { useRef, useState } from "react";
|
|
5
|
+
import { Button, IconButton } from "./button.js";
|
|
6
|
+
import { Avatar } from "./data-display.js";
|
|
7
|
+
import { Field, FieldError, FieldLabel, Form } from "./form-layout.js";
|
|
8
|
+
import { icon, Spinner } from "./icon.js";
|
|
9
|
+
import { Input } from "./input.js";
|
|
10
|
+
import { Cluster } from "./layout.js";
|
|
11
|
+
import { useCiridaeLocale } from "./locale.js";
|
|
12
|
+
import { Dialog } from "./overlays.js";
|
|
13
|
+
/*
|
|
14
|
+
* Edits the signed-in person's name and picture. The app saves them, so this works with any
|
|
15
|
+
* session; pass `trigger`, or `open` and `onOpenChange`. Each save settles on its own and the
|
|
16
|
+
* dialog stays open, so a new picture shows beside the name still being edited.
|
|
17
|
+
*/
|
|
18
|
+
const PICTURE_TYPES = "image/png,image/jpeg,image/webp";
|
|
19
|
+
const MAX_NAME_LENGTH = 256;
|
|
20
|
+
/** The server's reason for a rejected change, or `fallback` when it gave none. */
|
|
21
|
+
function failureMessage(error, fallback) {
|
|
22
|
+
return "detail" in error && typeof error.detail === "string" ? error.detail : fallback;
|
|
23
|
+
}
|
|
24
|
+
export function ProfileDialog({ name, email, pictureUrl, onSaveName, onSavePicture, onOpenChange, ...dialogProps }) {
|
|
25
|
+
const { labels: allLabels } = useCiridaeLocale();
|
|
26
|
+
const labels = allLabels.profileDialog;
|
|
27
|
+
const pictureInput = useRef(null);
|
|
28
|
+
const [draft, setDraft] = useState(name ?? "");
|
|
29
|
+
const trimmedDraft = draft.trim();
|
|
30
|
+
const rename = useMutation({ mutationFn: onSaveName });
|
|
31
|
+
const picture = useMutation({ mutationFn: onSavePicture });
|
|
32
|
+
return (_jsxs(Dialog, { ...dialogProps, kind: "info", onOpenChange: (open, details) => {
|
|
33
|
+
setDraft(name ?? "");
|
|
34
|
+
rename.reset();
|
|
35
|
+
picture.reset();
|
|
36
|
+
onOpenChange?.(open, details);
|
|
37
|
+
}, pending: rename.isPending || picture.isPending, title: labels.title, children: [_jsx(Avatar, { badge: _jsx(IconButton, { "aria-busy": picture.isPending || undefined, "aria-label": labels.changePicture, disabled: picture.isPending, onClick: () => pictureInput.current?.click(), size: "compact", variant: "primary", children: picture.isPending ? (_jsx(Spinner, { "aria-hidden": "true" })) : (_jsx(PlusIcon, { className: icon({ size: "small" }) })) }), color: "blue", label: name ?? email ?? "", size: "large", src: pictureUrl }), _jsx("input", { accept: PICTURE_TYPES, hidden: true, onChange: (event) => {
|
|
38
|
+
const file = event.target.files?.[0];
|
|
39
|
+
event.target.value = "";
|
|
40
|
+
if (file)
|
|
41
|
+
picture.mutate(file);
|
|
42
|
+
}, ref: pictureInput, type: "file" }), picture.error ? (_jsx(FieldError, { children: failureMessage(picture.error, labels.pictureFailed) })) : null, _jsxs(Form, { onSubmit: (event) => {
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
rename.mutate(trimmedDraft);
|
|
45
|
+
}, children: [_jsxs(Field, { children: [_jsx(FieldLabel, { children: labels.name }), _jsx(Input, { autoComplete: "name", maxLength: MAX_NAME_LENGTH, onChange: (event) => setDraft(event.target.value), value: draft })] }), rename.error ? (_jsx(FieldError, { children: failureMessage(rename.error, labels.nameFailed) })) : null, _jsx(Cluster, { children: _jsx(Button, { disabled: !trimmedDraft || trimmedDraft === name, loading: rename.isPending, type: "submit", children: labels.saveName }) })] })] }));
|
|
46
|
+
}
|
|
@@ -27,6 +27,13 @@ export type SelectProps = {
|
|
|
27
27
|
disabled?: boolean;
|
|
28
28
|
};
|
|
29
29
|
export declare function Select({ options, value, onValueChange, placeholder, label, size: controlSize, variant, name, required, disabled, }: SelectProps): import("react").JSX.Element;
|
|
30
|
+
export type MultiSelectProps = Pick<SelectProps, "options" | "placeholder" | "label" | "size" | "variant" | "disabled"> & {
|
|
31
|
+
value: readonly string[];
|
|
32
|
+
onValueChange: (value: string[]) => void;
|
|
33
|
+
onOpenChange?: (open: boolean) => void;
|
|
34
|
+
};
|
|
35
|
+
/** A `Select` that holds several options; its menu stays open while they are toggled. */
|
|
36
|
+
export declare function MultiSelect({ options, value, onValueChange, onOpenChange, placeholder, label, size: controlSize, variant, disabled, }: MultiSelectProps): import("react").JSX.Element;
|
|
30
37
|
export type SlicerProps = Omit<SelectProps, "size" | "variant" | "placeholder"> & {
|
|
31
38
|
/** What the slicer filters by, shown muted before the chosen value. */
|
|
32
39
|
label: string;
|
|
@@ -126,14 +126,33 @@ function density(size) {
|
|
|
126
126
|
function SelectMenu({ options, popupClassName, itemClassName, }) {
|
|
127
127
|
return (_jsx(BaseSelect.Portal, { children: _jsx(HotkeyLayer, { children: _jsx(BaseSelect.Positioner, { className: positioner, sideOffset: glassMenuOffsetFromTrigger, align: "start", alignItemWithTrigger: false, children: _jsx(BaseSelect.Popup, { className: popupClassName, "data-ciridae-ui": "", children: _jsx(BaseSelect.List, { className: list, children: options.map((option) => (_jsxs(BaseSelect.Item, { className: itemClassName, value: option.value, children: [_jsx(BaseSelect.ItemText, { children: option.label }), _jsx(BaseSelect.ItemIndicator, { className: itemIndicator, children: _jsx(CheckIcon, { className: icon({ size: "small" }) }) })] }, option.value))) }) }) }) }) }));
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
function SelectTrigger({ variant, size, label, children, }) {
|
|
130
130
|
const { labels } = useCiridaeLocale();
|
|
131
131
|
const fieldIds = useFieldControl({});
|
|
132
132
|
const inField = useInField();
|
|
133
|
+
return (_jsxs(BaseSelect.Trigger, { ...fieldIds, className: cx(trigger({ variant, size }), variant === "raised" && toolbarEdge.className), "aria-label": label ?? (inField ? undefined : labels.select.label), "data-ciridae-ui": "", "data-edge": variant === "raised" ? toolbarEdge["data-edge"] : undefined, children: [children, _jsx(BaseSelect.Icon, { children: _jsx(CaretDownIcon, { className: icon({ size: "small" }) }) })] }));
|
|
134
|
+
}
|
|
135
|
+
export function Select({ options, value, onValueChange, placeholder, label, size: controlSize = "small", variant = controlSize === "small" ? "raised" : "field", name, required, disabled, }) {
|
|
136
|
+
const { labels } = useCiridaeLocale();
|
|
133
137
|
const underline = variant === "underline";
|
|
134
138
|
// An underline trigger is sized to its value, so its menu may run wider, at its body text.
|
|
135
139
|
const size = underline ? "regular" : density(controlSize);
|
|
136
|
-
return (_jsxs(BaseSelect.Root, { items: options, value: value, onValueChange: onValueChange, name: name, required: required, disabled: disabled, children: [
|
|
140
|
+
return (_jsxs(BaseSelect.Root, { items: options, value: value, onValueChange: onValueChange, name: name, required: required, disabled: disabled, children: [_jsx(SelectTrigger, { variant: variant, size: size, label: label, children: _jsx(BaseSelect.Value, { placeholder: placeholder ?? labels.select.placeholder }) }), _jsx(SelectMenu, { options: options, popupClassName: underline ? popup.compact : popup[size], itemClassName: item[size] })] }));
|
|
141
|
+
}
|
|
142
|
+
/** A `Select` that holds several options; its menu stays open while they are toggled. */
|
|
143
|
+
export function MultiSelect({ options, value, onValueChange, onOpenChange, placeholder, label, size: controlSize = "small", variant = controlSize === "small" ? "raised" : "field", disabled, }) {
|
|
144
|
+
const { labels } = useCiridaeLocale();
|
|
145
|
+
// The trigger keeps its label while open, so toggling never resizes it and moves the menu.
|
|
146
|
+
const [valueWhenOpened, setValueWhenOpened] = useState(null);
|
|
147
|
+
const underline = variant === "underline";
|
|
148
|
+
const size = underline ? "regular" : density(controlSize);
|
|
149
|
+
return (_jsxs(BaseSelect.Root, { multiple: true, items: options, value: [...value], onValueChange: onValueChange, onOpenChange: (open) => {
|
|
150
|
+
setValueWhenOpened(open ? value : null);
|
|
151
|
+
onOpenChange?.(open);
|
|
152
|
+
}, disabled: disabled, children: [_jsx(SelectTrigger, { variant: variant, size: size, label: label, children: _jsx(BaseSelect.Value, { placeholder: placeholder ?? labels.select.placeholder, children: (selected) => options
|
|
153
|
+
.filter((option) => (valueWhenOpened ?? selected).includes(option.value))
|
|
154
|
+
.map((option) => option.label)
|
|
155
|
+
.join(", ") }) }), _jsx(SelectMenu, { options: options, popupClassName: underline ? popup.compact : popup[size], itemClassName: item[size] })] }));
|
|
137
156
|
}
|
|
138
157
|
/*
|
|
139
158
|
* A slicer is a filter's pill: the dimension it cuts by, then the value chosen, then the caret.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ciridae/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -202,6 +202,10 @@
|
|
|
202
202
|
"types": "./dist/components/chip.d.ts",
|
|
203
203
|
"default": "./dist/components/chip.js"
|
|
204
204
|
},
|
|
205
|
+
"./profile-dialog": {
|
|
206
|
+
"types": "./dist/components/profile-dialog.d.ts",
|
|
207
|
+
"default": "./dist/components/profile-dialog.js"
|
|
208
|
+
},
|
|
205
209
|
"./member-directory": {
|
|
206
210
|
"types": "./dist/components/member-directory.d.ts",
|
|
207
211
|
"default": "./dist/components/member-directory.js"
|