oneslash-design-system 2.16.0 → 2.17.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.
- package/README.md +1 -1
- package/dist/DESIGN.md +26 -3
- package/dist/cases/accept-invite/signed-in.jsx +1 -1
- package/dist/cases/accept-invite/signed-out.jsx +1 -1
- package/dist/cases/accept-invite.md +2 -2
- package/dist/cases/agent-options/cards.d.ts +1 -0
- package/dist/cases/agent-options/cards.jsx +91 -0
- package/dist/cases/agent-options.md +168 -0
- package/dist/cases/agent-pending-reply/steps.d.ts +1 -0
- package/dist/cases/agent-pending-reply/steps.jsx +149 -0
- package/dist/cases/agent-pending-reply/streaming.d.ts +1 -0
- package/dist/cases/agent-pending-reply/streaming.jsx +146 -0
- package/dist/cases/agent-pending-reply.md +432 -0
- package/dist/cases/agent-plan-proposal/changes.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/changes.jsx +224 -0
- package/dist/cases/agent-plan-proposal/steps.d.ts +1 -0
- package/dist/cases/agent-plan-proposal/steps.jsx +211 -0
- package/dist/cases/agent-plan-proposal.md +656 -0
- package/dist/cases/agent-question/choices.d.ts +1 -0
- package/dist/cases/agent-question/choices.jsx +132 -0
- package/dist/cases/agent-question/free-text.d.ts +1 -0
- package/dist/cases/agent-question/free-text.jsx +81 -0
- package/dist/cases/agent-question.md +338 -0
- package/dist/cases/agent-shows-sources.md +2 -2
- package/dist/cases/artifact-card/card.d.ts +1 -0
- package/dist/cases/artifact-card/card.jsx +45 -0
- package/dist/cases/artifact-card.md +103 -0
- package/dist/cases/composer-limit/notice-with-action.d.ts +1 -0
- package/dist/cases/composer-limit/notice-with-action.jsx +87 -0
- package/dist/cases/composer-limit/notice.d.ts +1 -0
- package/dist/cases/composer-limit/notice.jsx +84 -0
- package/dist/cases/composer-limit.md +286 -0
- package/dist/cases/conversation-starters/chips.d.ts +1 -0
- package/dist/cases/conversation-starters/chips.jsx +69 -0
- package/dist/cases/conversation-starters/none.d.ts +1 -0
- package/dist/cases/conversation-starters/none.jsx +45 -0
- package/dist/cases/conversation-starters.md +208 -0
- package/dist/cases/mention-list/in-composer.d.ts +1 -0
- package/dist/cases/mention-list/in-composer.jsx +169 -0
- package/dist/cases/mention-list.md +252 -0
- package/dist/cases/message-actions/hover-toolbar.d.ts +1 -0
- package/dist/cases/message-actions/hover-toolbar.jsx +229 -0
- package/dist/cases/message-actions/menu.d.ts +1 -0
- package/dist/cases/message-actions/menu.jsx +258 -0
- package/dist/cases/message-actions.md +651 -0
- package/dist/cases/message-attachments/in-composer.d.ts +1 -0
- package/dist/cases/message-attachments/in-composer.jsx +134 -0
- package/dist/cases/message-attachments/in-message.d.ts +1 -0
- package/dist/cases/message-attachments/in-message.jsx +46 -0
- package/dist/cases/message-attachments.md +310 -0
- package/dist/cases/message-composer/plain.d.ts +1 -0
- package/dist/cases/message-composer/plain.jsx +57 -0
- package/dist/cases/message-composer/with-tools.d.ts +1 -0
- package/dist/cases/message-composer/with-tools.jsx +182 -0
- package/dist/cases/message-composer.md +356 -0
- package/dist/cases/message-edit/in-place.d.ts +1 -0
- package/dist/cases/message-edit/in-place.jsx +99 -0
- package/dist/cases/message-edit.md +179 -0
- package/dist/cases/message-reactions/chips.d.ts +1 -0
- package/dist/cases/message-reactions/chips.jsx +118 -0
- package/dist/cases/message-reactions/quick-pick.d.ts +1 -0
- package/dist/cases/message-reactions/quick-pick.jsx +155 -0
- package/dist/cases/message-reactions.md +371 -0
- package/dist/cases/message-row/grouped.d.ts +1 -0
- package/dist/cases/message-row/grouped.jsx +56 -0
- package/dist/cases/message-row/person-and-agent.d.ts +1 -0
- package/dist/cases/message-row/person-and-agent.jsx +41 -0
- package/dist/cases/message-row.md +189 -0
- package/dist/cases/reply-feedback/thumbs.d.ts +1 -0
- package/dist/cases/reply-feedback/thumbs.jsx +191 -0
- package/dist/cases/reply-feedback/with-reason.d.ts +1 -0
- package/dist/cases/reply-feedback/with-reason.jsx +221 -0
- package/dist/cases/reply-feedback.md +552 -0
- package/dist/cases/reply-sources/cards.d.ts +1 -0
- package/dist/cases/reply-sources/cards.jsx +83 -0
- package/dist/cases/reply-sources/tag-only.d.ts +1 -0
- package/dist/cases/reply-sources/tag-only.jsx +45 -0
- package/dist/cases/reply-sources.md +247 -0
- package/dist/cases/slash-command-list/in-composer.d.ts +1 -0
- package/dist/cases/slash-command-list/in-composer.jsx +162 -0
- package/dist/cases/slash-command-list.md +247 -0
- package/dist/cases/success-feedback.md +1 -1
- package/dist/cases/typing-and-status/line.d.ts +1 -0
- package/dist/cases/typing-and-status/line.jsx +50 -0
- package/dist/cases/typing-and-status.md +96 -0
- package/dist/cases.json +1276 -14
- package/dist/components/button.d.ts +3 -2
- package/dist/components/button.jsx +9 -7
- package/dist/components/composer.d.ts +74 -0
- package/dist/components/composer.jsx +122 -0
- package/dist/components/fileChip.d.ts +33 -0
- package/dist/components/fileChip.jsx +61 -0
- package/dist/components/iconButton.d.ts +3 -3
- package/dist/components/iconButton.jsx +9 -7
- package/dist/components/layout.d.ts +7 -1
- package/dist/components/layout.jsx +5 -2
- package/dist/components/menu.d.ts +21 -0
- package/dist/components/menu.jsx +27 -3
- package/dist/components/menuItem.d.ts +9 -1
- package/dist/components/menuItem.jsx +5 -4
- package/dist/components/message.d.ts +28 -0
- package/dist/components/message.jsx +25 -0
- package/dist/components/paragraph.d.ts +3 -1
- package/dist/components/paragraph.jsx +2 -2
- package/dist/components/popover.d.ts +7 -1
- package/dist/components/popover.jsx +35 -9
- package/dist/components/radioGroup.d.ts +8 -1
- package/dist/components/radioGroup.jsx +19 -8
- package/dist/components/sourceCard.d.ts +23 -0
- package/dist/components/sourceCard.jsx +56 -0
- package/dist/components/stepList.d.ts +17 -0
- package/dist/components/stepList.jsx +79 -0
- package/dist/components/tag.d.ts +9 -1
- package/dist/components/tag.jsx +6 -4
- package/dist/components/textarea.jsx +3 -18
- package/dist/components/userImage.d.ts +9 -1
- package/dist/components/userImage.jsx +10 -3
- package/dist/internal/autoGrow.d.ts +11 -0
- package/dist/internal/autoGrow.js +28 -0
- package/dist/internal/composer.d.ts +16 -0
- package/dist/internal/composer.js +18 -0
- package/dist/internal/menu.d.ts +6 -0
- package/dist/internal/menu.js +31 -0
- package/dist/native-mapping.json +32 -1
- package/dist/stories/Button.stories.d.ts +1 -0
- package/dist/stories/Button.stories.jsx +17 -1
- package/dist/stories/Cases.generated.stories.d.ts +30 -0
- package/dist/stories/Cases.generated.stories.jsx +60 -0
- package/dist/stories/Composer.stories.d.ts +23 -0
- package/dist/stories/Composer.stories.jsx +121 -0
- package/dist/stories/FileChip.stories.d.ts +7 -0
- package/dist/stories/FileChip.stories.jsx +35 -0
- package/dist/stories/IconButton.stories.d.ts +1 -0
- package/dist/stories/IconButton.stories.jsx +18 -1
- package/dist/stories/Menu.stories.d.ts +4 -0
- package/dist/stories/Menu.stories.jsx +46 -1
- package/dist/stories/MenuItem.stories.d.ts +1 -0
- package/dist/stories/MenuItem.stories.jsx +8 -0
- package/dist/stories/Message.stories.d.ts +10 -0
- package/dist/stories/Message.stories.jsx +77 -0
- package/dist/stories/PageComponents.stories.d.ts +1 -0
- package/dist/stories/PageComponents.stories.jsx +21 -0
- package/dist/stories/RadioGroup.stories.d.ts +2 -0
- package/dist/stories/RadioGroup.stories.jsx +40 -1
- package/dist/stories/SourceCard.stories.d.ts +8 -0
- package/dist/stories/SourceCard.stories.jsx +33 -0
- package/dist/stories/StepList.stories.d.ts +8 -0
- package/dist/stories/StepList.stories.jsx +35 -0
- package/dist/stories/UserImage.stories.d.ts +2 -0
- package/dist/stories/UserImage.stories.jsx +19 -0
- package/package.json +4 -3
|
@@ -29,5 +29,6 @@ interface ButtonProps extends React.AriaAttributes {
|
|
|
29
29
|
/** The `<button>`'s own `type`. Use `submit` for a form's submit button. Defaults to `button`. */
|
|
30
30
|
htmlType?: 'button' | 'submit' | 'reset';
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
/** The ref reaches the `<button>`, or the `<a>` when `href` is set, so a page can move focus to it */
|
|
33
|
+
declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
|
|
34
|
+
export default Button;
|
|
@@ -21,12 +21,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
}
|
|
22
22
|
return t;
|
|
23
23
|
};
|
|
24
|
-
import React from 'react';
|
|
24
|
+
import React, { forwardRef } from 'react';
|
|
25
25
|
import NextLink from 'next/link';
|
|
26
26
|
import IconSlot from './iconSlot';
|
|
27
27
|
import { LoadingSmall } from './loadingScreen';
|
|
28
28
|
import { focusRing, focusRingDanger, pressFeedback, pressFeedbackAny, stateTransition } from './sharedStyles';
|
|
29
|
-
|
|
29
|
+
/** The ref reaches the `<button>`, or the `<a>` when `href` is set, so a page can move focus to it */
|
|
30
|
+
var Button = forwardRef(function Button(_a, ref) {
|
|
30
31
|
var size = _a.size, type = _a.type, _b = _a.color, color = _b === void 0 ? 'default' : _b, state = _a.state, label = _a.label, secondLabel = _a.secondLabel, decoIcon = _a.decoIcon, actionIcon = _a.actionIcon, onClickButton = _a.onClickButton, onClickActionIcon = _a.onClickActionIcon, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.loading, loading = _d === void 0 ? false : _d, href = _a.href, _e = _a.openInNewTab, openInNewTab = _e === void 0 ? false : _e, replace = _a.replace, _f = _a.htmlType, htmlType = _f === void 0 ? 'button' : _f, rest = __rest(_a, ["size", "type", "color", "state", "label", "secondLabel", "decoIcon", "actionIcon", "onClickButton", "onClickActionIcon", "className", "loading", "href", "openInNewTab", "replace", "htmlType"]);
|
|
31
32
|
var isLink = href !== undefined;
|
|
32
33
|
// Horizontal padding sits on the button so an icon and the label are inset equally
|
|
@@ -116,18 +117,19 @@ export default function Button(_a) {
|
|
|
116
117
|
if (isLink) {
|
|
117
118
|
// A link cannot be disabled: without an href it is not focusable and does nothing
|
|
118
119
|
if (state === 'disabled' || loading) {
|
|
119
|
-
return (<a {...rest} role="link" aria-disabled="true" aria-busy={loading || undefined} className={buttonClasses}>
|
|
120
|
+
return (<a {...rest} ref={ref} role="link" aria-disabled="true" aria-busy={loading || undefined} className={buttonClasses}>
|
|
120
121
|
{content}
|
|
121
122
|
</a>);
|
|
122
123
|
}
|
|
123
124
|
var linkProps = __assign(__assign(__assign({}, rest), { className: buttonClasses, onClick: onClickButton }), (openInNewTab && { target: '_blank', rel: 'noopener noreferrer' }));
|
|
124
125
|
// Same rule as Link: next/link for paths, a plain <a> for another site
|
|
125
126
|
if (href.startsWith('http://') || href.startsWith('https://')) {
|
|
126
|
-
return <a href={href} {...linkProps}>{content}</a>;
|
|
127
|
+
return <a href={href} {...linkProps} ref={ref}>{content}</a>;
|
|
127
128
|
}
|
|
128
|
-
return <NextLink href={href} replace={replace} {...linkProps}>{content}</NextLink>;
|
|
129
|
+
return <NextLink href={href} replace={replace} {...linkProps} ref={ref}>{content}</NextLink>;
|
|
129
130
|
}
|
|
130
|
-
return (<button {...rest} type={htmlType} className={buttonClasses} disabled={state === 'disabled' || loading} aria-busy={loading || undefined} onClick={onClickButton}>
|
|
131
|
+
return (<button {...rest} ref={ref} type={htmlType} className={buttonClasses} disabled={state === 'disabled' || loading} aria-busy={loading || undefined} onClick={onClickButton}>
|
|
131
132
|
{content}
|
|
132
133
|
</button>);
|
|
133
|
-
}
|
|
134
|
+
});
|
|
135
|
+
export default Button;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/** `role` and every `aria-*` prop are passed to the `<textarea>`, as is the ref */
|
|
3
|
+
interface ComposerProps extends React.AriaAttributes {
|
|
4
|
+
/** On the text area */
|
|
5
|
+
id: string;
|
|
6
|
+
value: string;
|
|
7
|
+
onChange: (value: string) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Called by Enter (see `submitOnEnter`) and by the send control when there is something to send
|
|
10
|
+
* (`canSubmit`) and the Composer is not `disabled` or `sending`. Enter with nothing to send does
|
|
11
|
+
* nothing. The Composer never clears `value` itself: the caller owns it and sets it to `''` once
|
|
12
|
+
* the message is taken.
|
|
13
|
+
*/
|
|
14
|
+
onSubmit: () => void;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
/** The text area's name. Required: the field has no visible label, and `placeholder` is not one. */
|
|
17
|
+
'aria-label': string;
|
|
18
|
+
/** On the text area: `combobox` while a mention or command list is attached to it */
|
|
19
|
+
role?: React.AriaRole;
|
|
20
|
+
/** The text area and the send control are disabled; `above` still shows. Disable your own `tools` and `actions`. */
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/** The text area grows from one line to this many, then scrolls */
|
|
23
|
+
maxRows?: number;
|
|
24
|
+
autoFocus?: boolean;
|
|
25
|
+
/** Inside the border, over the text: attachment chips, a notice, a suggestion list */
|
|
26
|
+
above?: React.ReactNode;
|
|
27
|
+
/** Bottom left, inside the border: `IconButton`s such as attach or mention the agent */
|
|
28
|
+
tools?: React.ReactNode;
|
|
29
|
+
/** Bottom right, in place of the send or stop control: 'Cancel' and 'Save' when editing a message.
|
|
30
|
+
* Enter still calls `onSubmit` under the same rule. */
|
|
31
|
+
actions?: React.ReactNode;
|
|
32
|
+
/** The send control's name, kept while it shows `sending` */
|
|
33
|
+
sendLabel?: string;
|
|
34
|
+
/** The send control shows that it is loading, and Enter does not send */
|
|
35
|
+
sending?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* When set, the send control becomes a stop control that calls this. Stop stays pressable whatever
|
|
38
|
+
* the text and `canSubmit`, and while `disabled`, so a run can always be stopped. With both `onStop`
|
|
39
|
+
* and `sending`, the stop control shows and Enter is blocked. With `onStop` and without `sending`, Enter
|
|
40
|
+
* still calls `onSubmit`: a message to the people in the thread while an agent runs.
|
|
41
|
+
*/
|
|
42
|
+
onStop?: () => void;
|
|
43
|
+
stopLabel?: string;
|
|
44
|
+
/** Whether there is something to send. Defaults to: the trimmed value is not empty. Set it when an
|
|
45
|
+
* attachment alone can be sent. It drives Enter and the send control, never Stop. */
|
|
46
|
+
canSubmit?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* `true` (default): Enter sends and Shift+Enter adds a line. `false`: Enter adds a line and only the
|
|
49
|
+
* send control sends. Cmd+Enter and Ctrl+Enter send in both. Option/Alt+Enter counts as Enter. Set `false` on touch devices, where
|
|
50
|
+
* Return should add a line; an Android soft keyboard may also report Enter as keyCode 229, which
|
|
51
|
+
* counts as composing and so never sends.
|
|
52
|
+
*/
|
|
53
|
+
submitOnEnter?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Called first, for every key. Call `preventDefault()` to take a key from the Composer: a suggestion
|
|
56
|
+
* list does this for the arrows, Enter and Escape. For Escape also call `stopPropagation()`, so a
|
|
57
|
+
* Modal around the Composer does not close (Select does the same).
|
|
58
|
+
*/
|
|
59
|
+
onKeyDown?: (event: React.KeyboardEvent<HTMLTextAreaElement>) => void;
|
|
60
|
+
/** On the text area, after the Composer's own focus tracking (the box's outline) */
|
|
61
|
+
onFocus?: (event: React.FocusEvent<HTMLTextAreaElement>) => void;
|
|
62
|
+
/** On the text area, after the Composer's own focus tracking. A suggestion list closes here. */
|
|
63
|
+
onBlur?: (event: React.FocusEvent<HTMLTextAreaElement>) => void;
|
|
64
|
+
/**
|
|
65
|
+
* React's `onSelect` on the text area: called while it has focus each time its caret or selection
|
|
66
|
+
* has moved, by typing, an arrow key, Home or End, a click or a drag. A key that leaves the caret
|
|
67
|
+
* where it was does not call it, and setting `value` does not call it by itself. Read
|
|
68
|
+
* `event.currentTarget.selectionStart` there: a suggestion list closes when the caret leaves the
|
|
69
|
+
* word it completes.
|
|
70
|
+
*/
|
|
71
|
+
onSelect?: (event: React.SyntheticEvent<HTMLTextAreaElement>) => void;
|
|
72
|
+
}
|
|
73
|
+
declare const Composer: React.ForwardRefExoticComponent<ComposerProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
74
|
+
export default Composer;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
14
|
+
import { ArrowUp, Square } from 'lucide-react';
|
|
15
|
+
import IconButton from './iconButton';
|
|
16
|
+
import { Cluster } from './layout';
|
|
17
|
+
import { stateTransition } from './sharedStyles';
|
|
18
|
+
import { fitToContent } from '../internal/autoGrow';
|
|
19
|
+
import { isComposing, shouldSubmit } from '../internal/composer';
|
|
20
|
+
// The outline the text area's focus gives the box: Textarea's focus look, on the border around everything
|
|
21
|
+
var focusedOutline = 'outline outline-1 outline-offset-2 outline-fg-primary';
|
|
22
|
+
// The message box: a text area with its tools inside one border. Enter sends, Shift+Enter adds a line,
|
|
23
|
+
// and Enter that confirms an input method's text (Korean, Japanese, Chinese) does neither.
|
|
24
|
+
var Composer = forwardRef(function Composer(_a, ref) {
|
|
25
|
+
var id = _a.id, value = _a.value, onChange = _a.onChange, onSubmit = _a.onSubmit, placeholder = _a.placeholder, ariaLabel = _a["aria-label"], _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.maxRows, maxRows = _c === void 0 ? 6 : _c, _d = _a.autoFocus, autoFocus = _d === void 0 ? false : _d, above = _a.above, tools = _a.tools, actions = _a.actions, _e = _a.sendLabel, sendLabel = _e === void 0 ? 'Send' : _e, _f = _a.sending, sending = _f === void 0 ? false : _f, onStop = _a.onStop, _g = _a.stopLabel, stopLabel = _g === void 0 ? 'Stop' : _g, canSubmit = _a.canSubmit, _h = _a.submitOnEnter, submitOnEnter = _h === void 0 ? true : _h, onKeyDown = _a.onKeyDown, onFocus = _a.onFocus, onBlur = _a.onBlur, onSelect = _a.onSelect, textareaProps = __rest(_a, ["id", "value", "onChange", "onSubmit", "placeholder", 'aria-label', "disabled", "maxRows", "autoFocus", "above", "tools", "actions", "sendLabel", "sending", "onStop", "stopLabel", "canSubmit", "submitOnEnter", "onKeyDown", "onFocus", "onBlur", "onSelect"]) // role and aria-*
|
|
26
|
+
;
|
|
27
|
+
var textareaRef = useRef(null);
|
|
28
|
+
useImperativeHandle(ref, function () { return textareaRef.current; }, []);
|
|
29
|
+
// Between compositionstart and compositionend
|
|
30
|
+
var composingRef = useRef(false);
|
|
31
|
+
var aboveRef = useRef(null);
|
|
32
|
+
var _j = useState(false), focused = _j[0], setFocused = _j[1];
|
|
33
|
+
var adjustHeight = useCallback(function () {
|
|
34
|
+
if (textareaRef.current)
|
|
35
|
+
fitToContent(textareaRef.current, maxRows);
|
|
36
|
+
}, [maxRows]);
|
|
37
|
+
// Also re-measure when the value changes from outside (e.g. cleared after submit)
|
|
38
|
+
useEffect(function () {
|
|
39
|
+
adjustHeight();
|
|
40
|
+
}, [adjustHeight, value]);
|
|
41
|
+
var hasSomething = canSubmit !== null && canSubmit !== void 0 ? canSubmit : value.trim() !== '';
|
|
42
|
+
var canSend = hasSomething && !disabled && !sending;
|
|
43
|
+
var handleKeyDown = function (e) {
|
|
44
|
+
if (onKeyDown)
|
|
45
|
+
onKeyDown(e);
|
|
46
|
+
if (e.defaultPrevented || e.key !== 'Enter')
|
|
47
|
+
return;
|
|
48
|
+
var composing = isComposing({
|
|
49
|
+
composing: composingRef.current,
|
|
50
|
+
nativeIsComposing: e.nativeEvent.isComposing,
|
|
51
|
+
keyCode: e.keyCode,
|
|
52
|
+
});
|
|
53
|
+
if (composing)
|
|
54
|
+
return; // The input method's Enter
|
|
55
|
+
var submitKey = e.metaKey || e.ctrlKey || (submitOnEnter && !e.shiftKey);
|
|
56
|
+
if (!submitKey)
|
|
57
|
+
return; // A new line
|
|
58
|
+
e.preventDefault(); // A send key never adds a line, even when there is nothing to send
|
|
59
|
+
var submit = shouldSubmit({
|
|
60
|
+
key: e.key,
|
|
61
|
+
shiftKey: e.shiftKey,
|
|
62
|
+
metaKey: e.metaKey,
|
|
63
|
+
ctrlKey: e.ctrlKey,
|
|
64
|
+
isComposing: composing,
|
|
65
|
+
canSubmit: hasSomething,
|
|
66
|
+
disabled: disabled,
|
|
67
|
+
sending: sending,
|
|
68
|
+
submitOnEnter: submitOnEnter,
|
|
69
|
+
});
|
|
70
|
+
if (submit)
|
|
71
|
+
onSubmit();
|
|
72
|
+
};
|
|
73
|
+
// Keep focus in the field: the send control disables once the message is taken
|
|
74
|
+
var handleSend = function () {
|
|
75
|
+
var _a;
|
|
76
|
+
onSubmit();
|
|
77
|
+
(_a = textareaRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
78
|
+
};
|
|
79
|
+
// A press on the box's padding or the empty part of a row goes to the text area. In `above`, only a
|
|
80
|
+
// suggestion row does that (focus stays in the field, the click still lands); text there stays selectable.
|
|
81
|
+
var handleMouseDown = function (e) {
|
|
82
|
+
var _a, _b;
|
|
83
|
+
var target = e.target;
|
|
84
|
+
if (disabled || target.closest('button, a, input, textarea'))
|
|
85
|
+
return;
|
|
86
|
+
if (((_a = aboveRef.current) === null || _a === void 0 ? void 0 : _a.contains(target)) && !target.closest('[role="option"],[role="menuitem"]'))
|
|
87
|
+
return;
|
|
88
|
+
e.preventDefault();
|
|
89
|
+
(_b = textareaRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
90
|
+
};
|
|
91
|
+
var boxClasses = disabled
|
|
92
|
+
? 'bg-transparent border-fg-disabled'
|
|
93
|
+
: "bg-background-default border-fg-disabled hover:border-fg-secondary cursor-text".concat(focused ? " ".concat(focusedOutline) : '');
|
|
94
|
+
var textClasses = disabled ? 'text-fg-disabled cursor-not-allowed' : 'text-fg-primary';
|
|
95
|
+
// IconButton names a loading button 'Loading'; aria-labelledby wins over that name
|
|
96
|
+
var sendLabelId = "".concat(id, "-send-label");
|
|
97
|
+
var control = actions !== null && actions !== void 0 ? actions : (onStop ? (<IconButton color="primary" state="enabled" size="small" icon={Square} ariaLabel={stopLabel} onClick={onStop}/>) : (<>
|
|
98
|
+
{sending && (<span id={sendLabelId} hidden>
|
|
99
|
+
{sendLabel}
|
|
100
|
+
</span>)}
|
|
101
|
+
<IconButton color="primary" state={canSend || sending ? 'enabled' : 'disabled'} size="small" icon={ArrowUp} ariaLabel={sendLabel} aria-labelledby={sending ? sendLabelId : undefined} loading={sending} onClick={canSend ? handleSend : undefined}/>
|
|
102
|
+
</>));
|
|
103
|
+
return (<div className={"flex flex-col gap-small w-full p-2 border rounded-control ".concat(stateTransition, " ").concat(boxClasses)} onMouseDown={handleMouseDown}>
|
|
104
|
+
{above && <div ref={aboveRef}>{above}</div>}
|
|
105
|
+
<textarea {...textareaProps} ref={textareaRef} id={id} rows={1} className={"block w-full px-1 bg-transparent outline-none resize-none [&::-webkit-scrollbar]:hidden text-body1 leading-[22px] placeholder:text-fg-disabled ".concat(textClasses)} value={value} onChange={function (e) { return onChange(e.target.value); }} onInput={adjustHeight} onKeyDown={handleKeyDown} onFocus={function (e) {
|
|
106
|
+
setFocused(true);
|
|
107
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(e);
|
|
108
|
+
}} onBlur={function (e) {
|
|
109
|
+
setFocused(false);
|
|
110
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(e);
|
|
111
|
+
}} onSelect={onSelect} onCompositionStart={function () {
|
|
112
|
+
composingRef.current = true;
|
|
113
|
+
}} onCompositionEnd={function () {
|
|
114
|
+
composingRef.current = false;
|
|
115
|
+
}} placeholder={placeholder} aria-label={ariaLabel} autoFocus={autoFocus} disabled={disabled} autoComplete="off"/>
|
|
116
|
+
<Cluster justify={tools ? 'between' : 'end'}>
|
|
117
|
+
{tools && <Cluster gap="small">{tools}</Cluster>}
|
|
118
|
+
{control}
|
|
119
|
+
</Cluster>
|
|
120
|
+
</div>);
|
|
121
|
+
});
|
|
122
|
+
export default Composer;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface FileChipProps {
|
|
3
|
+
/** One line; a longer name is cut at the end with an ellipsis */
|
|
4
|
+
name: string;
|
|
5
|
+
/** A short type label such as 'PDF', shown in a small tinted box before the name */
|
|
6
|
+
kind?: string;
|
|
7
|
+
/**
|
|
8
|
+
* One line of secondary text: the size, or the status. An uploading or failed chip
|
|
9
|
+
* does not announce its state in words, so put the words here ('Uploading', 'Upload failed').
|
|
10
|
+
* A change of `state` is not announced either: when it matters, the caller announces it in a live region.
|
|
11
|
+
*/
|
|
12
|
+
meta?: string;
|
|
13
|
+
/** Default `ready`. `uploading` shows a spinner in place of `kind` and sets `aria-busy`; `failed` shows an alert icon and the error color. */
|
|
14
|
+
state?: 'ready' | 'uploading' | 'failed';
|
|
15
|
+
/**
|
|
16
|
+
* Adds a remove button beside the name. A failed chip can still be removed. After it runs, the
|
|
17
|
+
* caller moves focus: to the next chip, or to the message box when none is left.
|
|
18
|
+
*/
|
|
19
|
+
onRemove?: () => void;
|
|
20
|
+
/** Default `Remove <name>` */
|
|
21
|
+
removeLabel?: string;
|
|
22
|
+
/** Makes the name part a link. A path goes through `next/link`; an `http(s)://` URL is a plain `<a>`. */
|
|
23
|
+
href?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Makes the name part a button. Ignored when `href` is set: the link wins and `onClick` does not run.
|
|
26
|
+
* A retry for a failed chip is the caller's: pass `onClick` that retries, and a `meta` such as 'Failed. Try again'.
|
|
27
|
+
*/
|
|
28
|
+
onClick?: () => void;
|
|
29
|
+
/** With `href`: open in a new tab. Another site (`http(s)://`) always opens in a new tab. */
|
|
30
|
+
openInNewTab?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export default function FileChip({ name, kind, meta, state, onRemove, removeLabel, href, onClick, openInNewTab, }: FileChipProps): React.JSX.Element;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
import React from 'react';
|
|
14
|
+
import NextLink from 'next/link';
|
|
15
|
+
import { AlertCircle, X } from 'lucide-react';
|
|
16
|
+
import IconButton from './iconButton';
|
|
17
|
+
import { LoadingSmall } from './loadingScreen';
|
|
18
|
+
import { focusRing, stateTransition } from './sharedStyles';
|
|
19
|
+
// A file attached to a message, waiting in the message box or already sent. One row, at most
|
|
20
|
+
// 28rem wide so a long name does not stretch it. The name part is the link or button; the remove
|
|
21
|
+
// button is its sibling, never inside it. With no `href` and no `onClick` the name is static text.
|
|
22
|
+
export default function FileChip(_a) {
|
|
23
|
+
var name = _a.name, kind = _a.kind, meta = _a.meta, _b = _a.state, state = _b === void 0 ? 'ready' : _b, onRemove = _a.onRemove, removeLabel = _a.removeLabel, href = _a.href, onClick = _a.onClick, _c = _a.openInNewTab, openInNewTab = _c === void 0 ? false : _c;
|
|
24
|
+
var failed = state === 'failed';
|
|
25
|
+
var interactive = href !== undefined || onClick !== undefined;
|
|
26
|
+
var nameClasses = "flex min-w-0 flex-1 items-center gap-2 rounded-control text-left".concat(interactive ? " cursor-pointer ".concat(stateTransition, " ").concat(focusRing) : '');
|
|
27
|
+
var lead = state === 'uploading' ? (
|
|
28
|
+
// The caller says "Uploading" in `meta`; the spinner's own "Loading" status is hidden.
|
|
29
|
+
<span aria-hidden="true" className="flex size-6 shrink-0 items-center justify-center text-fg-primary">
|
|
30
|
+
<LoadingSmall size="tiny"/>
|
|
31
|
+
</span>) : failed ? (<AlertCircle role="img" aria-label="Failed" className="size-6 shrink-0 p-1 text-error-text" strokeWidth={2}/>) : kind ? (<span aria-hidden="true" className="flex h-6 shrink-0 items-center rounded-inline bg-background-accent300 px-1.5 text-caption text-fg-primary">
|
|
32
|
+
{kind}
|
|
33
|
+
</span>) : null;
|
|
34
|
+
var content = (<>
|
|
35
|
+
{lead}
|
|
36
|
+
<span className="truncate text-body2 text-fg-primary">{name}</span>
|
|
37
|
+
{meta && <span className={"shrink-0 text-caption ".concat(failed ? 'text-error-text' : 'text-fg-secondary')}>{meta}</span>}
|
|
38
|
+
</>);
|
|
39
|
+
// A link or button is named in one string: the failed state first, then the name and the meta.
|
|
40
|
+
// Static, the name and the meta are separate flex items, so they are read as separate words.
|
|
41
|
+
var label = [failed && 'Failed', name, meta].filter(Boolean).join(', ');
|
|
42
|
+
var main;
|
|
43
|
+
if (href !== undefined) {
|
|
44
|
+
var isExternal = href.startsWith('http://') || href.startsWith('https://');
|
|
45
|
+
var newTab = openInNewTab || isExternal;
|
|
46
|
+
var props = __assign({ className: "".concat(nameClasses, " hover:bg-background-accent200"), 'aria-label': label }, (newTab && { target: '_blank', rel: 'noopener noreferrer' }));
|
|
47
|
+
main = newTab ? <a href={href} {...props}>{content}</a> : <NextLink href={href} {...props}>{content}</NextLink>;
|
|
48
|
+
}
|
|
49
|
+
else if (onClick) {
|
|
50
|
+
main = (<button type="button" className={"".concat(nameClasses, " hover:bg-background-accent200")} onClick={onClick} aria-label={label}>
|
|
51
|
+
{content}
|
|
52
|
+
</button>);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
main = <span className={nameClasses}>{content}</span>;
|
|
56
|
+
}
|
|
57
|
+
return (<div aria-busy={state === 'uploading' ? true : undefined} className={"inline-flex max-w-md items-center gap-1 rounded-control border px-2 py-1 ".concat(failed ? 'border-error-main' : 'border-fg-disabled')}>
|
|
58
|
+
{main}
|
|
59
|
+
{onRemove && (<IconButton color="iconOnly" state="enabled" size="small" icon={X} ariaLabel={removeLabel !== null && removeLabel !== void 0 ? removeLabel : "Remove ".concat(name)} onClick={onRemove}/>)}
|
|
60
|
+
</div>);
|
|
61
|
+
}
|
|
@@ -24,6 +24,6 @@ interface IconButtonProps extends React.AriaAttributes {
|
|
|
24
24
|
/** With `href` to a path: replace the current history entry instead of adding one */
|
|
25
25
|
replace?: boolean;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export
|
|
27
|
+
/** The ref reaches the `<button>`, or the `<a>` when `href` is set, so a page can move focus to it */
|
|
28
|
+
declare const IconButton: React.ForwardRefExoticComponent<IconButtonProps & React.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
|
|
29
|
+
export default IconButton;
|
|
@@ -21,12 +21,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
}
|
|
22
22
|
return t;
|
|
23
23
|
};
|
|
24
|
-
import React from 'react';
|
|
24
|
+
import React, { forwardRef } from 'react';
|
|
25
25
|
import NextLink from 'next/link';
|
|
26
26
|
import IconSlot from './iconSlot';
|
|
27
27
|
import { LoadingSmall } from './loadingScreen';
|
|
28
28
|
import { focusRing, pressFeedback, pressFeedbackAny, stateTransition } from './sharedStyles';
|
|
29
|
-
|
|
29
|
+
/** The ref reaches the `<button>`, or the `<a>` when `href` is set, so a page can move focus to it */
|
|
30
|
+
var IconButton = forwardRef(function IconButton(_a, ref) {
|
|
30
31
|
var color = _a.color, state = _a.state, size = _a.size, iconName = _a.iconName, icon = _a.icon, onClick = _a.onClick, _b = _a.loading, loading = _b === void 0 ? false : _b, // Default to false
|
|
31
32
|
ariaLabel = _a.ariaLabel, href = _a.href, _c = _a.openInNewTab, openInNewTab = _c === void 0 ? false : _c, replace = _a.replace, rest = __rest(_a, ["color", "state", "size", "iconName", "icon", "onClick", "loading", "ariaLabel", "href", "openInNewTab", "replace"]);
|
|
32
33
|
var isLink = href !== undefined;
|
|
@@ -108,19 +109,20 @@ export default function IconButton(_a) {
|
|
|
108
109
|
if (isLink) {
|
|
109
110
|
// A link cannot be disabled: without an href it is not focusable and does nothing
|
|
110
111
|
if (isDisabled || loading) {
|
|
111
|
-
return (<a {...rest} role="link" aria-disabled="true" className={className} aria-label={loading ? 'Loading' : label}>
|
|
112
|
+
return (<a {...rest} ref={ref} role="link" aria-disabled="true" className={className} aria-label={loading ? 'Loading' : label}>
|
|
112
113
|
{content}
|
|
113
114
|
</a>);
|
|
114
115
|
}
|
|
115
116
|
var linkProps = __assign(__assign(__assign({}, rest), { className: className, onClick: onClick, 'aria-label': label }), (openInNewTab && { target: '_blank', rel: 'noopener noreferrer' }));
|
|
116
117
|
// Same rule as Link: next/link for paths, a plain <a> for another site
|
|
117
118
|
if (href.startsWith('http://') || href.startsWith('https://')) {
|
|
118
|
-
return <a href={href} {...linkProps}>{content}</a>;
|
|
119
|
+
return <a href={href} {...linkProps} ref={ref}>{content}</a>;
|
|
119
120
|
}
|
|
120
|
-
return <NextLink href={href} replace={replace} {...linkProps}>{content}</NextLink>;
|
|
121
|
+
return <NextLink href={href} replace={replace} {...linkProps} ref={ref}>{content}</NextLink>;
|
|
121
122
|
}
|
|
122
|
-
return (<button {...rest} type="button" className={className} disabled={isDisabled || loading} // Disable button during loading
|
|
123
|
+
return (<button {...rest} ref={ref} type="button" className={className} disabled={isDisabled || loading} // Disable button during loading
|
|
123
124
|
onClick={onClick} aria-label={loading ? 'Loading' : label}>
|
|
124
125
|
{content}
|
|
125
126
|
</button>);
|
|
126
|
-
}
|
|
127
|
+
});
|
|
128
|
+
export default IconButton;
|
|
@@ -10,7 +10,13 @@ interface StackProps extends LayoutProps {
|
|
|
10
10
|
align?: 'stretch' | 'start';
|
|
11
11
|
}
|
|
12
12
|
export declare function Stack({ children, gap, align, className }: StackProps): React.JSX.Element;
|
|
13
|
-
|
|
13
|
+
interface ClusterProps extends LayoutProps {
|
|
14
|
+
/** `between` pushes the first and last child to the ends; `end` packs the row to the right. */
|
|
15
|
+
justify?: 'start' | 'between' | 'end';
|
|
16
|
+
/** `start` lines the children up along the top edge; `center` along the middle. */
|
|
17
|
+
align?: 'center' | 'start';
|
|
18
|
+
}
|
|
19
|
+
export declare function Cluster({ children, gap, justify, align, className }: ClusterProps): React.JSX.Element;
|
|
14
20
|
interface GridProps extends LayoutProps {
|
|
15
21
|
/** How many columns from the medium breakpoint up. Below it: two for `compact`, otherwise one. */
|
|
16
22
|
columns?: 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
@@ -13,10 +13,13 @@ export function Stack(_a) {
|
|
|
13
13
|
var children = _a.children, _b = _a.gap, gap = _b === void 0 ? 'large' : _b, _c = _a.align, align = _c === void 0 ? 'stretch' : _c, _d = _a.className, className = _d === void 0 ? '' : _d;
|
|
14
14
|
return <div className={"flex flex-col ".concat(align === 'start' ? 'items-start' : '', " ").concat(gaps[gap], " ").concat(className)}>{children}</div>;
|
|
15
15
|
}
|
|
16
|
+
var clusterJustify = { start: '', between: ' justify-between', end: ' justify-end' };
|
|
16
17
|
// Things that sit in a row and wrap, a spacing token apart.
|
|
17
18
|
export function Cluster(_a) {
|
|
18
|
-
var children = _a.children, _b = _a.gap, gap = _b === void 0 ? 'medium' : _b, _c = _a.className, className =
|
|
19
|
-
return <div className={"flex flex-wrap items-center ".concat(gaps[gap], " ").concat(className)}>
|
|
19
|
+
var children = _a.children, _b = _a.gap, gap = _b === void 0 ? 'medium' : _b, _c = _a.justify, justify = _c === void 0 ? 'start' : _c, _d = _a.align, align = _d === void 0 ? 'center' : _d, _e = _a.className, className = _e === void 0 ? '' : _e;
|
|
20
|
+
return (<div className={"flex flex-wrap ".concat(align === 'start' ? 'items-start' : 'items-center', " ").concat(gaps[gap]).concat(clusterJustify[justify], " ").concat(className)}>
|
|
21
|
+
{children}
|
|
22
|
+
</div>);
|
|
20
23
|
}
|
|
21
24
|
var mdColumns = {
|
|
22
25
|
2: 'md:grid-cols-2',
|
|
@@ -3,6 +3,27 @@ interface MenuProps {
|
|
|
3
3
|
children: React.ReactNode;
|
|
4
4
|
width?: number | string;
|
|
5
5
|
className?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Makes the list a keyboard menu (`role="menu"`): on mount it focuses its first item; ArrowDown and
|
|
8
|
+
* ArrowUp move to the next and previous item and wrap, Home and End go to the first and last, and a
|
|
9
|
+
* letter moves to the next item whose label starts with it. The items are the `role="menuitem"`
|
|
10
|
+
* descendants (MenuItem's default role), skipping any with `aria-disabled="true"`. Keys move real
|
|
11
|
+
* focus and leave each item's tabIndex as it is. Open it in a `Popover` with `returnFocus` so Escape,
|
|
12
|
+
* Tab, Shift+Tab and a chosen item close it and give focus back to the trigger. Items with `href` are
|
|
13
|
+
* links without the menuitem role, so the keys skip them: use `onClick` items in a navigable Menu.
|
|
14
|
+
*/
|
|
15
|
+
navigable?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The list element's role; wins over the `role="menu"` that `navigable` sets. For a suggestion list
|
|
18
|
+
* (mentions, commands) pass `role="listbox"` and an `id` that the text area's `aria-controls` points at,
|
|
19
|
+
* without `navigable`: the Menu then adds no focus or key handling, and the caller drives
|
|
20
|
+
* `MenuItem role="option" isActive` and `aria-activedescendant` itself, as Select does.
|
|
21
|
+
*/
|
|
22
|
+
role?: string;
|
|
23
|
+
/** On the list element, for `aria-controls` */
|
|
24
|
+
id?: string;
|
|
25
|
+
/** The list's name, such as 'Message actions'. Set only when the list has a role (`role` or `navigable`). */
|
|
26
|
+
'aria-label'?: string;
|
|
6
27
|
}
|
|
7
28
|
declare const Menu: React.ForwardRefExoticComponent<MenuProps & React.RefAttributes<HTMLDivElement>>;
|
|
8
29
|
export default Menu;
|
package/dist/components/menu.jsx
CHANGED
|
@@ -1,11 +1,35 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import React, { forwardRef } from 'react';
|
|
2
|
+
import React, { forwardRef, useEffect, useRef } from 'react';
|
|
3
|
+
import { nextIndex } from '../internal/menu';
|
|
4
|
+
var ITEMS = '[role="menuitem"]:not([aria-disabled="true"])';
|
|
3
5
|
var Menu = forwardRef(function (_a, ref) {
|
|
4
|
-
var children = _a.children, width = _a.width, _b = _a.className, className = _b === void 0 ? '' : _b;
|
|
6
|
+
var children = _a.children, width = _a.width, _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.navigable, navigable = _c === void 0 ? false : _c, role = _a.role, id = _a.id, ariaLabel = _a["aria-label"];
|
|
7
|
+
var listRole = role !== null && role !== void 0 ? role : (navigable ? 'menu' : undefined);
|
|
8
|
+
var listRef = useRef(null);
|
|
9
|
+
var items = function () { var _a, _b; return Array.from((_b = (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(ITEMS)) !== null && _b !== void 0 ? _b : []); };
|
|
10
|
+
// Inside a Popover the Menu mounts once the anchor is set, so this runs as the menu opens
|
|
11
|
+
useEffect(function () {
|
|
12
|
+
var _a;
|
|
13
|
+
if (navigable)
|
|
14
|
+
(_a = items()[0]) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
|
15
|
+
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
16
|
+
var handleKeyDown = function (e) {
|
|
17
|
+
if (e.altKey || e.ctrlKey || e.metaKey)
|
|
18
|
+
return;
|
|
19
|
+
var list = items();
|
|
20
|
+
var item = e.target.closest('[role="menuitem"]');
|
|
21
|
+
var current = item ? list.indexOf(item) : -1;
|
|
22
|
+
var labels = list.map(function (el) { var _a; return (_a = el.textContent) !== null && _a !== void 0 ? _a : ''; });
|
|
23
|
+
var next = nextIndex({ key: e.key, current: current, count: list.length, labels: labels });
|
|
24
|
+
if (next === current || next < 0)
|
|
25
|
+
return;
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
list[next].focus();
|
|
28
|
+
};
|
|
5
29
|
// dark-only edge: a ring only in dark mode, so it keeps a dark: variant (it follows whatever dark variant the app's preset/@theme defines, class-only or OS-aware)
|
|
6
30
|
return (<div ref={ref} className={"\n bg-background-overlay\n rounded-container\n shadow-overlay\n dark:ring-1 dark:ring-misc-divider\n overflow-hidden\n ".concat(className, "\n ")} style={{ width: width || 'auto' }}>
|
|
7
31
|
{/* 4px padding keeps the 8px item corners concentric with the 12px menu corners */}
|
|
8
|
-
<div className="p-1 flex flex-col gap-0.5">
|
|
32
|
+
<div ref={listRef} id={id} role={listRole} aria-label={listRole ? ariaLabel : undefined} onKeyDown={navigable ? handleKeyDown : undefined} className="p-1 flex flex-col gap-0.5">
|
|
9
33
|
{children}
|
|
10
34
|
</div>
|
|
11
35
|
</div>);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
interface MenuItemProps {
|
|
3
|
+
/** Renders the row as a link. The link has no `role`, so a navigable Menu's arrow keys skip it: use `onClick` items there. */
|
|
3
4
|
href?: string;
|
|
4
5
|
iconName?: string;
|
|
5
6
|
icon?: React.ReactNode;
|
|
@@ -24,8 +25,15 @@ interface MenuItemProps {
|
|
|
24
25
|
id?: string;
|
|
25
26
|
/** Keyboard highlight used by Select's listbox */
|
|
26
27
|
isActive?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Only with `role="option"`: wins over the `aria-selected` computed from `isSelected`. In a suggestion
|
|
30
|
+
* list (mentions, commands) pass `aria-selected={isActive}` so it follows the highlighted row.
|
|
31
|
+
*/
|
|
32
|
+
'aria-selected'?: boolean;
|
|
27
33
|
/** Select keeps focus on its trigger and passes -1 */
|
|
28
34
|
tabIndex?: number;
|
|
35
|
+
/** `danger` gives the label and the left icon the error text color, for Delete and the like. `isSelected` wins over it. */
|
|
36
|
+
color?: 'default' | 'danger';
|
|
29
37
|
}
|
|
30
|
-
export default function MenuItem({ href, iconName, icon, userHandle, userImgUrl, label, secondLabel, isSelected, onClick, className, size, tag, iconRight, rightAction, role, id, isActive, tabIndex, }: MenuItemProps): React.JSX.Element;
|
|
38
|
+
export default function MenuItem({ href, iconName, icon, userHandle, userImgUrl, label, secondLabel, isSelected, onClick, className, size, tag, iconRight, rightAction, role, id, isActive, 'aria-selected': ariaSelected, tabIndex, color, }: MenuItemProps): React.JSX.Element;
|
|
31
39
|
export {};
|
|
@@ -7,7 +7,7 @@ import Tag from './tag';
|
|
|
7
7
|
import { focusRing, pressFeedbackAny, stateTransition } from './sharedStyles';
|
|
8
8
|
export default function MenuItem(_a) {
|
|
9
9
|
var _b;
|
|
10
|
-
var href = _a.href, iconName = _a.iconName, icon = _a.icon, userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, label = _a.label, secondLabel = _a.secondLabel, isSelected = _a.isSelected, onClick = _a.onClick, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.size, size = _d === void 0 ? 'medium' : _d, tag = _a.tag, iconRight = _a.iconRight, rightAction = _a.rightAction, _e = _a.role, role = _e === void 0 ? 'menuitem' : _e, id = _a.id, _f = _a.isActive, isActive = _f === void 0 ? false : _f, _g = _a.tabIndex, tabIndex = _g === void 0 ? 0 : _g;
|
|
10
|
+
var href = _a.href, iconName = _a.iconName, icon = _a.icon, userHandle = _a.userHandle, userImgUrl = _a.userImgUrl, label = _a.label, secondLabel = _a.secondLabel, isSelected = _a.isSelected, onClick = _a.onClick, _c = _a.className, className = _c === void 0 ? '' : _c, _d = _a.size, size = _d === void 0 ? 'medium' : _d, tag = _a.tag, iconRight = _a.iconRight, rightAction = _a.rightAction, _e = _a.role, role = _e === void 0 ? 'menuitem' : _e, id = _a.id, _f = _a.isActive, isActive = _f === void 0 ? false : _f, ariaSelected = _a["aria-selected"], _g = _a.tabIndex, tabIndex = _g === void 0 ? 0 : _g, _h = _a.color, color = _h === void 0 ? 'default' : _h;
|
|
11
11
|
// Size-based icon and text classes
|
|
12
12
|
var iconSize = { tiny: 'w-4 h-4', small: 'w-5 h-5', medium: 'w-6 h-6' }[size];
|
|
13
13
|
var labelClass = { tiny: 'text-caption', small: 'text-body2', medium: 'text-body1' }[size];
|
|
@@ -15,9 +15,10 @@ export default function MenuItem(_a) {
|
|
|
15
15
|
// One step smaller than the row so a tag never makes its row taller
|
|
16
16
|
var tagSize = { tiny: 'tiny', small: 'tiny', medium: 'small' }[size];
|
|
17
17
|
var paddingClass = size === 'tiny' ? 'p-1' : 'p-2';
|
|
18
|
+
var danger = color === 'danger' && !isSelected;
|
|
18
19
|
var content = (<div id={id} role={href ? undefined : role}
|
|
19
20
|
// A link wrapper is already focusable; otherwise the row itself takes focus
|
|
20
|
-
tabIndex={href ? undefined : tabIndex} aria-selected={role === 'option' ? !!isSelected : undefined} className={"\n flex items-center ".concat(paddingClass, " rounded-control cursor-pointer justify-between text-left ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(isSelected
|
|
21
|
+
tabIndex={href ? undefined : tabIndex} aria-selected={role === 'option' ? ariaSelected !== null && ariaSelected !== void 0 ? ariaSelected : !!isSelected : undefined} className={"\n flex items-center ".concat(paddingClass, " rounded-control cursor-pointer justify-between text-left ").concat(stateTransition, " ").concat(pressFeedbackAny, " ").concat(focusRing, "\n ").concat(isSelected
|
|
21
22
|
? 'bg-primary-dark text-primary-contrast'
|
|
22
23
|
: "hover:bg-background-accent200 ".concat(isActive ? 'bg-background-accent200' : ''), "\n ").concat(className, "\n ")} style={{ width: '100%' }} onClick={onClick} onKeyDown={function (e) {
|
|
23
24
|
if (!href && e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) {
|
|
@@ -27,9 +28,9 @@ export default function MenuItem(_a) {
|
|
|
27
28
|
}}>
|
|
28
29
|
{/* Left group: icon/userImg + label with 8px gap */}
|
|
29
30
|
<div className="flex items-center gap-2 min-w-0">
|
|
30
|
-
{userImgUrl ? (<UserImage userHandle={userHandle || ''} userImgUrl={userImgUrl}/>) : icon ? (<span className={"".concat(iconSize, " flex-shrink-0 flex items-center justify-center")}>{icon}</span>) : (<IconSlot icon={iconName} className={"".concat(iconSize, " flex-shrink-0 ").concat(isSelected ? 'text-primary-contrast' : 'text-fg-secondary')}/>)}
|
|
31
|
+
{userImgUrl ? (<UserImage userHandle={userHandle || ''} userImgUrl={userImgUrl}/>) : icon ? (<span className={"".concat(iconSize, " flex-shrink-0 flex items-center justify-center").concat(danger ? ' text-error-text' : '')}>{icon}</span>) : (<IconSlot icon={iconName} className={"".concat(iconSize, " flex-shrink-0 ").concat(isSelected ? 'text-primary-contrast' : danger ? 'text-error-text' : 'text-fg-secondary')}/>)}
|
|
31
32
|
<div className="flex flex-col min-w-0">
|
|
32
|
-
<span className={"truncate ".concat(labelClass, " ").concat(isSelected ? 'text-primary-contrast' : 'text-fg-primary')}>
|
|
33
|
+
<span className={"truncate ".concat(labelClass, " ").concat(isSelected ? 'text-primary-contrast' : danger ? 'text-error-text' : 'text-fg-primary')}>
|
|
33
34
|
{label}
|
|
34
35
|
</span>
|
|
35
36
|
{secondLabel && (<span className={"truncate ".concat(secondLabelClass, " opacity-70 ").concat(isSelected ? 'text-primary-contrast' : 'text-fg-primary')}>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface MessageProps {
|
|
3
|
+
/** A `UserImage`, in a 24px slot on the left. Not shown when `compact`. */
|
|
4
|
+
avatar?: React.ReactNode;
|
|
5
|
+
/** The sender, at the start of the header line */
|
|
6
|
+
name?: string;
|
|
7
|
+
/** Shown after the name on the header line: a `Tag`, a model line, a `TimeStamp` */
|
|
8
|
+
meta?: React.ReactNode;
|
|
9
|
+
/** The body */
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
/** Under the body: sources, attachments, reactions */
|
|
12
|
+
footer?: React.ReactNode;
|
|
13
|
+
/** A row of `IconButton`s at the top right. Shown while the pointer is on the row or focus is inside it, and always on a device without hover.
|
|
14
|
+
* Keep them to quick actions; a control that must always be visible, such as Stop, belongs in `footer`. */
|
|
15
|
+
actions?: React.ReactNode;
|
|
16
|
+
/** Shows the actions at all times, for example while a menu opened from one of them is open, so its button stays on screen */
|
|
17
|
+
actionsVisible?: boolean;
|
|
18
|
+
/** A follow-on message from the same sender: no avatar and no header; the body lines up with the one above */
|
|
19
|
+
compact?: boolean;
|
|
20
|
+
/** `highlight` gives the row the accent100 background, for a search hit or a mention */
|
|
21
|
+
tone?: 'default' | 'highlight';
|
|
22
|
+
/** Pass it on every row, compact ones too, with the sender and the time: a compact row shows neither. */
|
|
23
|
+
'aria-label'?: string;
|
|
24
|
+
/** On the row, so a search hit can scroll to it */
|
|
25
|
+
id?: string;
|
|
26
|
+
}
|
|
27
|
+
export default function Message({ avatar, name, meta, children, footer, actions, actionsVisible, compact, tone, 'aria-label': ariaLabel, id, }: MessageProps): React.JSX.Element;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { stateTransition } from './sharedStyles';
|
|
3
|
+
var tones = { default: '', highlight: ' bg-background-accent100' };
|
|
4
|
+
// Opacity only: the actions stay in the tab order, so focus inside the row can reveal them,
|
|
5
|
+
// and they take their space at all times, so showing them moves nothing.
|
|
6
|
+
var actionsReveal = 'opacity-0 group-hover/message:opacity-100 group-focus-within/message:opacity-100 [@media(hover:none)]:opacity-100';
|
|
7
|
+
// One message in a chat list. The list that holds the rows owns `role="log"` (or `feed`), not the row.
|
|
8
|
+
// A named group, so `group-hover:` marks inside the body (RadioGroup, Checkbox) ignore the row,
|
|
9
|
+
// and an outer `.group` does not reveal the actions.
|
|
10
|
+
export default function Message(_a) {
|
|
11
|
+
var avatar = _a.avatar, name = _a.name, meta = _a.meta, children = _a.children, footer = _a.footer, actions = _a.actions, _b = _a.actionsVisible, actionsVisible = _b === void 0 ? false : _b, _c = _a.compact, compact = _c === void 0 ? false : _c, _d = _a.tone, tone = _d === void 0 ? 'default' : _d, ariaLabel = _a["aria-label"], id = _a.id;
|
|
12
|
+
var header = !compact && (name || meta);
|
|
13
|
+
return (<article id={id} aria-label={ariaLabel} className={"group/message flex items-start gap-medium px-2 py-1 rounded-control".concat(tones[tone])}>
|
|
14
|
+
<div className="flex-shrink-0 w-6">{compact ? null : avatar}</div>
|
|
15
|
+
<div className="flex flex-col flex-1 min-w-0 gap-small">
|
|
16
|
+
{header && (<div className="flex flex-wrap items-center gap-medium">
|
|
17
|
+
{name && <span className="min-w-0 break-words text-body1 font-medium text-fg-primary">{name}</span>}
|
|
18
|
+
{meta}
|
|
19
|
+
</div>)}
|
|
20
|
+
<div className="break-words">{children}</div>
|
|
21
|
+
{footer && <div>{footer}</div>}
|
|
22
|
+
</div>
|
|
23
|
+
{actions && <div className={"flex flex-shrink-0 items-center gap-small ".concat(actionsVisible ? '' : "".concat(actionsReveal, " ")).concat(stateTransition)}>{actions}</div>}
|
|
24
|
+
</article>);
|
|
25
|
+
}
|