Skip to content

Commit 2db7dfd

Browse files
committed
Document Alert, Card, Switch and Text
1 parent 864002d commit 2db7dfd

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed

src/ui/experimental/Alert.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
import { UiNode, element } from "../internal.js";
22

33
type AlertProps = {
4+
/**
5+
* The type of alert. Affects e.g. its visual styling.
6+
* Default value: "info".
7+
*/
48
type?: "info" | "success" | "warning" | "error";
9+
/**
10+
* A title or heading for the alert.
11+
* Optional, but recommended for providing a concise summary of the alert's content.
12+
*/
513
title?: string;
14+
/**
15+
* The main content of the alert. This can be text or more complex UI elements.
16+
*/
617
children?: UiNode;
718
};
819

20+
/**
21+
* A component for displaying an alert message to the user.
22+
*
23+
* Alerts can be used to communicate errors and warnings, but also
24+
* general feedback like acknowledgements for successful actions
25+
* or neutral informational messages.
26+
*
27+
* @example
28+
* ```tsx
29+
* <Alert type="error" title="Something went wrong">
30+
* An error occurred while processing your request.
31+
* </Alert>
32+
* ```
33+
* */
934
export function Alert(props: AlertProps): UiNode {
1035
return element("ui-alert", props);
1136
}

src/ui/experimental/Card.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
import { UiNode, element } from "../internal.js";
22

33
type CardProps = {
4+
/**
5+
* The content to be displayed inside the card.
6+
* Can include text or other UI components.
7+
*/
48
children?: UiNode;
59
};
610

11+
/**
12+
* A card-like container.
13+
*
14+
* Can hold various types of content. Often used to group related
15+
* information.
16+
*
17+
* @example
18+
* ```tsx
19+
* <Card>
20+
* Hello, World!
21+
* </Card>
22+
* ```
23+
* */
724
export function Card(props: CardProps): UiNode {
825
return element("ui-card", props);
926
}

src/ui/experimental/Switch.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,66 @@
11
import { Json, UiNode, element } from "../internal.js";
22

33
type SwitchProps = {
4+
/**
5+
* An optional name for the switch input element.
6+
*
7+
* Used as the name for the switch value when client state is submitted
8+
* to the UI endpoint. The value is send as a boolean (on as `true`,
9+
* off as `false`).
10+
*
11+
* When not defined, the switch value is not sent as a part of client state.
12+
*/
413
name?: string;
14+
/**
15+
* The text label associated with the switch.
16+
* Improves usability and accessibility by providing context for the switch.
17+
*/
518
label?: string;
19+
/**
20+
* If defined (i.e. not `undefined`), toggling the switch submits the `action`
21+
* value with client input state to the UI endpoint.
22+
*/
623
action?: Json;
24+
/**
25+
* Determines whether the switch is in the on (true) or off (false) state.
26+
* Default value: false.
27+
*/
728
checked?: boolean;
29+
/**
30+
* If true, the switch will be uninteractable and visually indicate
31+
* its disabled state.
32+
* Default value: false.
33+
*/
834
disabled?: boolean;
935
};
1036

37+
/**
38+
* A component that renders a toggle switch control.
39+
* Switches are used for binary choices, typically to turn a specific
40+
* feature or option on or off.
41+
*
42+
* @example
43+
* ```tsx
44+
* <Switch
45+
* name="notifications"
46+
* label="Enable notifications"
47+
* checked={true}
48+
* />
49+
* ```
50+
*
51+
* @example
52+
* When the `action` property is defined, its value is immediately
53+
* submitted to the UI endpoint when the switch is toggled. The surrounding
54+
* client input data is sent along with the action.
55+
*
56+
* ```tsx
57+
* <Switch
58+
* label="Enable notifications"
59+
* checked={true}
60+
* action={{ notifications: true }}
61+
* />
62+
* ```
63+
* */
1164
export function Switch(props: SwitchProps): UiNode {
1265
return element("ui-switch", props);
1366
}

src/ui/experimental/Text.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,62 @@
11
import { Responsive, UiNode, element } from "../internal.js";
22

33
type TextProps = {
4+
/**
5+
* Size of the text. Can be responsive.
6+
* Inherited from surrounding context if not explicitly set.
7+
*/
48
size?: Responsive<"xs" | "sm" | "md" | "lg">;
9+
/**
10+
* Horizontal text alignment. Can be responsive.
11+
* Inherited from surrounding context if not explicitly set.
12+
*/
513
align?: Responsive<"left" | "center" | "right">;
14+
/**
15+
* Font weight of the text. Can be responsive.
16+
* Inherited from surrounding context if not explicitly set.
17+
*/
618
weight?: Responsive<"regular" | "medium" | "semibold">;
19+
/**
20+
* Accent color of the text.
21+
* Inherited from surrounding context if not explicitly set.
22+
*/
723
color?: "base" | "gray" | "red" | "orange" | "yellow" | "green" | "blue";
24+
/**
25+
* If true, the text will be truncated with an ellipsis if it exceeds
26+
* the width of its container.
27+
* Default value: false.
28+
*/
829
truncate?: boolean;
30+
/**
31+
* The content to be displayed. Can be a string or more complex UI elements.
32+
*/
933
children?: UiNode;
1034
};
1135

36+
/**
37+
* A component for rendering text with various styling options.
38+
* Provides control over e.g. size, alignment, weight, color, and truncation
39+
* of text.
40+
*
41+
* @example
42+
* ```tsx
43+
* <Text size="lg" weight="semibold" color="blue">
44+
* This is a large, semibold, blue text.
45+
* </Text>
46+
* ```
47+
*
48+
* When not explicitly set, most properties inherit their values from the
49+
* surrounding context.
50+
*
51+
* @example
52+
* ```tsx
53+
* <Text color="semibold">
54+
* <Text weight="red">
55+
* This is a semibold, red text.
56+
* </Text>
57+
* <Text>
58+
* ```
59+
* */
1260
export function Text(props: TextProps): UiNode {
1361
return element("ui-text", props);
1462
}

0 commit comments

Comments
 (0)