jsl-ui 10.4.3 → 10.4.5
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/docs/AutoSuggestComponent.md +17 -17
- package/docs/ButtonComponent.md +22 -22
- package/docs/CheckBoxComponent.md +12 -12
- package/docs/DataBinding.md +19 -19
- package/docs/DateComponent.md +12 -12
- package/docs/DateRangeComponent.md +13 -13
- package/docs/DateTimeComponent.md +14 -14
- package/docs/DialogComponent.md +15 -15
- package/docs/DropdownMenuComponent.md +22 -22
- package/docs/ExpanderComponent.md +13 -13
- package/docs/FormComponent.md +15 -15
- package/docs/FormFieldComponent.md +15 -15
- package/docs/GridComponent.md +39 -39
- package/docs/InputComponent.md +15 -15
- package/docs/IntervalComponent.md +13 -13
- package/docs/LoadingComponent.md +12 -12
- package/docs/NavigationComponent.md +17 -17
- package/docs/Notification.md +14 -14
- package/docs/NotificationComponent.md +13 -13
- package/docs/NumberComponent.md +12 -12
- package/docs/OverlayComponent.md +13 -13
- package/docs/ProgressComponent.md +12 -12
- package/docs/README.md +27 -27
- package/docs/RibbonMenuComponent.md +14 -14
- package/docs/SelectComponent.md +36 -36
- package/docs/SliderComponent.md +20 -20
- package/docs/SplitterComponent.md +14 -14
- package/docs/StackPanelComponent.md +13 -13
- package/docs/TabsComponent.md +16 -16
- package/docs/TimeComponent.md +13 -13
- package/docs/TreeViewComponent.md +16 -16
- package/examples/showcase/checks-and-expanders.ts +148 -148
- package/examples/showcase/cultures.ts +39 -39
- package/examples/showcase/data-binding.ts +138 -138
- package/examples/showcase/dates.ts +168 -168
- package/examples/showcase/dialogs.ts +184 -184
- package/examples/showcase/dropdown-menus.ts +99 -99
- package/examples/showcase/feedback-and-navigation.ts +173 -173
- package/examples/showcase/fields.ts +166 -166
- package/examples/showcase/fonts/OFL-BricolageGrotesque.txt +93 -93
- package/examples/showcase/fonts/OFL-Figtree.txt +93 -93
- package/examples/showcase/fonts/OFL-Jost.txt +93 -93
- package/examples/showcase/generate-sources.cjs +104 -104
- package/examples/showcase/grids.ts +484 -484
- package/examples/showcase/index.html +71 -71
- package/examples/showcase/layout-and-navigation.ts +46 -46
- package/examples/showcase/nivona.css +98 -98
- package/examples/showcase/package.json +10 -10
- package/examples/showcase/selects.ts +184 -184
- package/examples/showcase/showcase-sources.ts +94 -94
- package/examples/showcase/showcase.css +281 -281
- package/examples/showcase/showcase.ts +244 -244
- package/examples/showcase/tabs.ts +161 -161
- package/examples/showcase/themes.css +83 -83
- package/examples/showcase/themes.ts +56 -56
- package/examples/showcase/wirtshans.css +65 -65
- package/lib/components/checkbox/CheckBoxStyle.scss +73 -73
- package/lib/components/date-range/DateRangeStyle.scss +35 -35
- package/lib/components/date-time/DateTimeStyle.scss +9 -9
- package/lib/components/dialog/DialogComponent.d.ts +9 -2
- package/lib/components/dialog/DialogComponent.js +17 -51
- package/lib/components/dropdown-menu/DropdownMenuStyle.scss +48 -48
- package/lib/components/expander/ExpanderStyle.scss +61 -61
- package/lib/components/form-field/FormFieldStyle.scss +36 -36
- package/lib/components/host/RenderHost.d.ts +25 -0
- package/lib/components/host/RenderHost.js +63 -0
- package/lib/components/loading/LoadingStyle.css +18 -18
- package/lib/components/navigation/NavigationStyle.scss +61 -61
- package/lib/components/notification/Notification.scss +102 -102
- package/lib/components/overlay/OverlayComponent.d.ts +9 -1
- package/lib/components/overlay/OverlayComponent.js +22 -13
- package/lib/components/overlay/overlay.css +15 -15
- package/lib/components/progress/ProgressStyle.scss +4 -4
- package/lib/components/ribbon-menu/RibbonMenuStyle.scss +5 -5
- package/lib/components/select/SelectStyle.scss +207 -207
- package/lib/components/slider/SliderStyle.scss +21 -21
- package/lib/components/slider/nouislider.css +15 -15
- package/lib/components/stack-panel/SplitterStyle.scss +8 -8
- package/lib/components/stack-panel/StackPanelStyle.scss +10 -10
- package/lib/components/tabs/TabsStyle.scss +139 -139
- package/lib/components/time/TimeComponent.scss +3 -3
- package/lib/components/tree-view/TreeViewStyle.scss +14 -14
- package/lib/core/helper.js +11 -6
- package/lib/grid/plugins/slick.headermenu.css +98 -98
- package/lib/grid.css +840 -3532
- package/lib/index.css.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/ui/auto.suggest.css +30 -30
- package/lib/ui/button.css +147 -147
- package/lib/ui/date-input.css +10 -10
- package/lib/ui/date.picker/css/tiny-date-picker.css +124 -124
- package/lib/ui/dialog.css +144 -144
- package/lib/ui/input.css +35 -35
- package/lib/ui/theme.css +28 -28
- package/package.json +1 -1
|
@@ -1,184 +1,184 @@
|
|
|
1
|
-
import { IJSLComponent, IJSLVNode } from "jsl-render";
|
|
2
|
-
import { SelectComponent } from "../../components/select/SelectComponent";
|
|
3
|
-
import { ButtonComponent } from "../../components/button/ButtonComponent";
|
|
4
|
-
import { DialogComponent } from "../../components/dialog/DialogComponent";
|
|
5
|
-
|
|
6
|
-
type Content = IJSLVNode | IJSLComponent;
|
|
7
|
-
const text = (tag: string, content: string, className?: string): IJSLVNode => ({ tag, content, attr: { class: className } });
|
|
8
|
-
const group = (children: Content[], className?: string): IJSLVNode => ({ tag: "div", attr: { class: className }, children });
|
|
9
|
-
const status = (content: string): IJSLVNode => ({ tag: "p", content, attr: { class: "sample-status", role: "status" } });
|
|
10
|
-
const field = (id: string, label: string, control: Content) => group([
|
|
11
|
-
{ tag: "label", content: label, attr: { for: id } }, control
|
|
12
|
-
], "select-showcase-field");
|
|
13
|
-
const action = (content: string, click: () => void) => new ButtonComponent({ content, click, type: "button", outlined: true, size: "small" });
|
|
14
|
-
const projects = [
|
|
15
|
-
{ value: "website", text: "Website refresh" }, { value: "library", text: "Component library" },
|
|
16
|
-
{ value: "workspace", text: "Team workspace" }, { value: "mobile", text: "Mobile experience" },
|
|
17
|
-
{ value: "research", text: "Customer research" }, { value: "release", text: "Autumn release" }
|
|
18
|
-
];
|
|
19
|
-
const skills = [
|
|
20
|
-
{ value: "design", text: "Design" }, { value: "typescript", text: "TypeScript" },
|
|
21
|
-
{ value: "accessibility", text: "Accessibility" }, { value: "testing", text: "Testing" },
|
|
22
|
-
{ value: "research", text: "Research" }, { value: "documentation", text: "Documentation" }
|
|
23
|
-
];
|
|
24
|
-
const singleStatus = status("No project selected.");
|
|
25
|
-
const single = new SelectComponent({
|
|
26
|
-
id: "select-project", data: projects, placeholder: "Choose a project", ariaLabel: "Project",
|
|
27
|
-
onChange: (value, item) => { singleStatus.content = item ? "Selected: " + item.text + " (" + value + ")" : "Selection cleared."; }
|
|
28
|
-
});
|
|
29
|
-
const multiStatus = status("2 skills selected.");
|
|
30
|
-
const multi = new SelectComponent({
|
|
31
|
-
id: "select-skills", data: skills, multiple: true, value: ["design", "typescript"],
|
|
32
|
-
placeholder: "Add skills", ariaLabel: "Skills",
|
|
33
|
-
onChange: (values, items) => {
|
|
34
|
-
const names = (items as unknown as typeof skills).map(item => item.text);
|
|
35
|
-
multiStatus.content = values.length ? values.length + " selected: " + names.join(", ") : "No skills selected.";
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
const locations = [
|
|
39
|
-
{ value: "vienna", text: "Vienna", region: "Europe" }, { value: "berlin", text: "Berlin", region: "Europe" },
|
|
40
|
-
{ value: "copenhagen", text: "Copenhagen", region: "Europe" }, { value: "tokyo", text: "Tokyo", region: "Asia Pacific" },
|
|
41
|
-
{ value: "singapore", text: "Singapore", region: "Asia Pacific" }, { value: "sydney", text: "Sydney", region: "Asia Pacific" },
|
|
42
|
-
{ value: "new-york", text: "New York", region: "Americas" }, { value: "toronto", text: "Toronto", region: "Americas" }
|
|
43
|
-
];
|
|
44
|
-
const groupStatus = status("Choose one or more offices.");
|
|
45
|
-
const people = [
|
|
46
|
-
{ value: "maya", text: "Maya Chen", initials: "MC", role: "Product designer" },
|
|
47
|
-
{ value: "alex", text: "Alex Morgan", initials: "AM", role: "Frontend engineer" },
|
|
48
|
-
{ value: "sam", text: "Sam Rivera", initials: "SR", role: "Accessibility specialist" },
|
|
49
|
-
{ value: "jules", text: "Jules Martin", initials: "JM", role: "Product manager" }
|
|
50
|
-
];
|
|
51
|
-
const memberStatus = status("Selected Maya Chen.");
|
|
52
|
-
const member = new SelectComponent({
|
|
53
|
-
id: "select-owner", data: people, value: "maya",
|
|
54
|
-
ariaLabel: "Project owner", placeholder: "Assign an owner", rowHeight: 56,
|
|
55
|
-
matchSearch: (item, term) => (item.text + " " + item.role).toLowerCase().includes(term.toLowerCase()),
|
|
56
|
-
onRender: args => args.isCurrent ? text("span", args.data.text) : group([
|
|
57
|
-
{ tag: "span", content: args.data.initials, attr: { class: "select-person-avatar", "aria-hidden": "true" } },
|
|
58
|
-
group([text("strong", args.data.text), text("span", args.data.role)], "select-person-copy")
|
|
59
|
-
], "select-person"),
|
|
60
|
-
onChange: (_value, item) => { memberStatus.content = item ? "Selected " + item.text + "." : "No owner selected."; }
|
|
61
|
-
});
|
|
62
|
-
const largeStatus = status("Search by name or jump through the list with your keyboard.");
|
|
63
|
-
const large = new SelectComponent({
|
|
64
|
-
id: "select-large", data: Array.from({ length: 10000 }, (_, i) => ({ value: i + 1, text: "Item " + ("00000" + (i + 1)).slice(-5) })),
|
|
65
|
-
value: 5000, ariaLabel: "Large list", dropdownHeight: "18rem", placeholder: "Choose an item",
|
|
66
|
-
onChange: (value, item) => { largeStatus.content = item ? "Selected " + item.text + ", key " + value : "Selection cleared."; }
|
|
67
|
-
});
|
|
68
|
-
// A pretend server: 500 customers, searched and paged with a delay.
|
|
69
|
-
const customerNames = Array.from({ length: 500 }, (_, i) => ({ value: i + 1, text: "Customer " + ("000" + (i + 1)).slice(-4) + " " + ["Alpine", "Danube", "Linz", "Graz", "Tyrol"][i % 5] }));
|
|
70
|
-
const remoteStatus = status("Open the list, type a name or scroll for more.");
|
|
71
|
-
let remoteGeneration = 0;
|
|
72
|
-
let remoteFound: typeof customerNames = [];
|
|
73
|
-
let remoteTerm = "";
|
|
74
|
-
function remoteLoad(append: boolean) {
|
|
75
|
-
const generation = ++remoteGeneration;
|
|
76
|
-
remote.setLoading(true);
|
|
77
|
-
setTimeout(() => {
|
|
78
|
-
if (generation !== remoteGeneration) { return; }
|
|
79
|
-
const matches = customerNames.filter(item => item.text.toLowerCase().includes(remoteTerm.toLowerCase()));
|
|
80
|
-
remoteFound = matches.slice(0, append ? remoteFound.length + 25 : 25);
|
|
81
|
-
remote.setData(remoteFound, remoteFound.length < matches.length);
|
|
82
|
-
remote.setLoading(false);
|
|
83
|
-
remoteStatus.content = remoteFound.length + " of " + matches.length + " matches loaded.";
|
|
84
|
-
}, 400);
|
|
85
|
-
}
|
|
86
|
-
const remote: SelectComponent = new SelectComponent({
|
|
87
|
-
id: "select-remote", data: [], ariaLabel: "Customer", placeholder: "Choose a customer", searchPlaceholder: "Search customers…",
|
|
88
|
-
onOpen: () => { if (!remoteFound.length) { remoteLoad(false); } },
|
|
89
|
-
onSearch: term => { remoteTerm = term; remoteLoad(false); },
|
|
90
|
-
onLoadMore: () => remoteLoad(true)
|
|
91
|
-
});
|
|
92
|
-
function card(id: string, number: string, title: string, description: string, children: Content[]): IJSLVNode {
|
|
93
|
-
return { tag: "article", attr: { id, class: "sample-card" }, children: [
|
|
94
|
-
group([text("span", number, "sample-number"), text("h3", title)], "card-heading"),
|
|
95
|
-
text("p", description, "card-description"), ...children
|
|
96
|
-
] };
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export const selectShowcase: IJSLVNode = {
|
|
100
|
-
tag: "section", attr: { id: "selects", class: "component-section", "aria-labelledby": "selects-title" }, children: [
|
|
101
|
-
group([
|
|
102
|
-
group([
|
|
103
|
-
text("p", "THE ESSENTIALS / 08", "eyebrow"),
|
|
104
|
-
{ tag: "h2", content: "Selects", attr: { id: "selects-title", class: "section-title" } },
|
|
105
|
-
text("p", "One choice or a few. Search, select, and keep the options easy to scan.", "hero-description")
|
|
106
|
-
], "hero-copy"),
|
|
107
|
-
group([
|
|
108
|
-
text("span", "INTERACTIVE PREVIEW", "preview-caption"),
|
|
109
|
-
field("select-preview-single", "Project", new SelectComponent({
|
|
110
|
-
id: "select-preview-single", data: projects, value: "library", ariaLabel: "Preview project"
|
|
111
|
-
})),
|
|
112
|
-
field("select-preview-multi", "Skills", new SelectComponent({
|
|
113
|
-
id: "select-preview-multi", data: skills, multiple: true, value: ["design", "typescript"], ariaLabel: "Preview skills"
|
|
114
|
-
}))
|
|
115
|
-
], "hero-preview select-hero-preview")
|
|
116
|
-
], "hero"),
|
|
117
|
-
group([
|
|
118
|
-
text("span", "Overview", "overview-label"), text("span", "Single & multiple", "overview-stat"),
|
|
119
|
-
text("span", "Search & groups", "overview-stat"), text("span", "Keyboard accessible", "overview-stat")
|
|
120
|
-
], "overview-bar"),
|
|
121
|
-
group([
|
|
122
|
-
card("select-single", "01", "A single choice", "A searchable list with a clear selection. Choose a project, then clear it to start again.", [
|
|
123
|
-
field("select-project", "Project", single), singleStatus,
|
|
124
|
-
text("pre", '{ data: projects, placeholder: "Choose a project" }', "sample-code")
|
|
125
|
-
]),
|
|
126
|
-
card("select-multiple", "02", "A collection of choices", "Selected items become compact chips. Toggle checked options while keeping the list open.", [
|
|
127
|
-
field("select-skills", "Skills", multi), multiStatus,
|
|
128
|
-
text("p", "Enter toggles the focused option. Escape finishes and returns focus to the field.", "inline-note"),
|
|
129
|
-
text("pre", '{ multiple: true, value: ["design", "typescript"] }', "sample-code")
|
|
130
|
-
]),
|
|
131
|
-
card("select-grouped", "03", "Options with context", "Group related options. Search filters the items and preserves their headings.", [
|
|
132
|
-
field("select-offices", "Offices", new SelectComponent({
|
|
133
|
-
id: "select-offices", data: locations, groupProperty: "region", multiple: true,
|
|
134
|
-
ariaLabel: "Offices", placeholder: "Choose offices",
|
|
135
|
-
onChange: values => { groupStatus.content = values.length ? values.length + " offices selected." : "Choose one or more offices."; }
|
|
136
|
-
})), groupStatus,
|
|
137
|
-
action("Try inside a dialog", () => {
|
|
138
|
-
DialogComponent.show({
|
|
139
|
-
header: "Choose a project", width: "28rem",
|
|
140
|
-
content: group([
|
|
141
|
-
text("p", "Select a project. Escape closes the options first.", "card-description"),
|
|
142
|
-
field("select-dialog-project", "Project", new SelectComponent({
|
|
143
|
-
id: "select-dialog-project", data: projects, ariaLabel: "Dialog project", placeholder: "Choose a project"
|
|
144
|
-
}))
|
|
145
|
-
]),
|
|
146
|
-
footer: group([DialogComponent.Cancel(), DialogComponent.Ok()], "sample-row")
|
|
147
|
-
});
|
|
148
|
-
})
|
|
149
|
-
]),
|
|
150
|
-
card("select-custom", "04", "More than a label", "Custom rows add useful details about each person.", [
|
|
151
|
-
field("select-owner", "Project owner", member), memberStatus,
|
|
152
|
-
text("p", "Search also matches each person's role.", "inline-note")
|
|
153
|
-
]),
|
|
154
|
-
card("select-states", "05", "The right level of choice", "Search can be omitted for short lists. Required selections and disabled controls share the same design.", [
|
|
155
|
-
field("select-required", "Default project", new SelectComponent({
|
|
156
|
-
id: "select-required", data: projects.slice(0, 3), value: "library", ariaLabel: "Default project",
|
|
157
|
-
enableSearch: false, allowEmpty: false
|
|
158
|
-
})),
|
|
159
|
-
field("select-disabled", "Unavailable project", new SelectComponent({
|
|
160
|
-
id: "select-disabled", data: projects, value: "website", enabled: false, ariaLabel: "Unavailable project"
|
|
161
|
-
})),
|
|
162
|
-
field("select-disabled-multi", "Unavailable skills", new SelectComponent({
|
|
163
|
-
id: "select-disabled-multi", data: skills, multiple: true, value: ["design", "testing"], enabled: false, ariaLabel: "Unavailable skills"
|
|
164
|
-
}))
|
|
165
|
-
]),
|
|
166
|
-
card("select-scale", "06", "Room for a long list", "Ten thousand options, with only the visible rows rendered. Selection stays in view when you open the list.", [
|
|
167
|
-
field("select-large", "Item", large), largeStatus,
|
|
168
|
-
text("p", "Type to search. Arrow keys move through results; Ctrl+Home and Ctrl+End jump to either end.", "inline-note")
|
|
169
|
-
]),
|
|
170
|
-
card("select-server", "07", "Search on the server", "For lists too long to load. The one search box asks the server, and scrolling to the end loads more.", [
|
|
171
|
-
field("select-remote", "Customer", remote), remoteStatus,
|
|
172
|
-
text("pre", '{ onSearch: term => load(term), onLoadMore: () => loadMore() } // answer with select.setData(items, hasMore)', "sample-code")
|
|
173
|
-
])
|
|
174
|
-
], "sample-grid select-sample-grid"),
|
|
175
|
-
{ tag: "details", attr: { class: "usage" }, children: [
|
|
176
|
-
text("summary", "Select usage & compatibility"),
|
|
177
|
-
text("pre", 'new SelectComponent({\n data: [{ value: "design", text: "Design" }, { value: "code", text: "Code" }],\n multiple: true,\n value: ["design"],\n placeholder: "Choose skills",\n ariaLabel: "Skills",\n onChange: (keys, items) => console.log(keys, items)\n});', "sample-code"),
|
|
178
|
-
text("p", "Existing data, keyColumn, textColumn, grouping, render callbacks, converters, popup sizing, and onAppend options remain available. The original placehoder spelling remains supported; placeholder takes precedence. Optional id, ariaLabel, ariaLabelledBy, searchPlaceholder, emptyText, and clearButtonLabel help label and translate the control."),
|
|
179
|
-
text("p", "getValue() returns a key or an array of keys. getSelected() returns the corresponding item or items. setValue() updates the selection silently; setSelected() also raises onChange. toggle(), show(), close(), focus(), isExpanded(), and destroy() are retained. Unmounting cleans up the owning popup."),
|
|
180
|
-
text("p", "Arrow Down, Arrow Up, Enter, and Space open the list. Type to search, use arrow keys to navigate, and Enter to select. Multi-select stays open as options are toggled. Escape returns to the field; Tab continues to the next control. In a list without search, Home/End jump to the ends and Space toggles an option. With search, use Ctrl+Home/End."),
|
|
181
|
-
text("p", "The default multi-select display shows up to three chips and a count for additional items. Custom onRender callbacks still receive the full selected array when isCurrent is true. Keep custom row content decorative; selection is handled by the option itself.")
|
|
182
|
-
] }
|
|
183
|
-
]
|
|
184
|
-
};
|
|
1
|
+
import { IJSLComponent, IJSLVNode } from "jsl-render";
|
|
2
|
+
import { SelectComponent } from "../../components/select/SelectComponent";
|
|
3
|
+
import { ButtonComponent } from "../../components/button/ButtonComponent";
|
|
4
|
+
import { DialogComponent } from "../../components/dialog/DialogComponent";
|
|
5
|
+
|
|
6
|
+
type Content = IJSLVNode | IJSLComponent;
|
|
7
|
+
const text = (tag: string, content: string, className?: string): IJSLVNode => ({ tag, content, attr: { class: className } });
|
|
8
|
+
const group = (children: Content[], className?: string): IJSLVNode => ({ tag: "div", attr: { class: className }, children });
|
|
9
|
+
const status = (content: string): IJSLVNode => ({ tag: "p", content, attr: { class: "sample-status", role: "status" } });
|
|
10
|
+
const field = (id: string, label: string, control: Content) => group([
|
|
11
|
+
{ tag: "label", content: label, attr: { for: id } }, control
|
|
12
|
+
], "select-showcase-field");
|
|
13
|
+
const action = (content: string, click: () => void) => new ButtonComponent({ content, click, type: "button", outlined: true, size: "small" });
|
|
14
|
+
const projects = [
|
|
15
|
+
{ value: "website", text: "Website refresh" }, { value: "library", text: "Component library" },
|
|
16
|
+
{ value: "workspace", text: "Team workspace" }, { value: "mobile", text: "Mobile experience" },
|
|
17
|
+
{ value: "research", text: "Customer research" }, { value: "release", text: "Autumn release" }
|
|
18
|
+
];
|
|
19
|
+
const skills = [
|
|
20
|
+
{ value: "design", text: "Design" }, { value: "typescript", text: "TypeScript" },
|
|
21
|
+
{ value: "accessibility", text: "Accessibility" }, { value: "testing", text: "Testing" },
|
|
22
|
+
{ value: "research", text: "Research" }, { value: "documentation", text: "Documentation" }
|
|
23
|
+
];
|
|
24
|
+
const singleStatus = status("No project selected.");
|
|
25
|
+
const single = new SelectComponent({
|
|
26
|
+
id: "select-project", data: projects, placeholder: "Choose a project", ariaLabel: "Project",
|
|
27
|
+
onChange: (value, item) => { singleStatus.content = item ? "Selected: " + item.text + " (" + value + ")" : "Selection cleared."; }
|
|
28
|
+
});
|
|
29
|
+
const multiStatus = status("2 skills selected.");
|
|
30
|
+
const multi = new SelectComponent({
|
|
31
|
+
id: "select-skills", data: skills, multiple: true, value: ["design", "typescript"],
|
|
32
|
+
placeholder: "Add skills", ariaLabel: "Skills",
|
|
33
|
+
onChange: (values, items) => {
|
|
34
|
+
const names = (items as unknown as typeof skills).map(item => item.text);
|
|
35
|
+
multiStatus.content = values.length ? values.length + " selected: " + names.join(", ") : "No skills selected.";
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const locations = [
|
|
39
|
+
{ value: "vienna", text: "Vienna", region: "Europe" }, { value: "berlin", text: "Berlin", region: "Europe" },
|
|
40
|
+
{ value: "copenhagen", text: "Copenhagen", region: "Europe" }, { value: "tokyo", text: "Tokyo", region: "Asia Pacific" },
|
|
41
|
+
{ value: "singapore", text: "Singapore", region: "Asia Pacific" }, { value: "sydney", text: "Sydney", region: "Asia Pacific" },
|
|
42
|
+
{ value: "new-york", text: "New York", region: "Americas" }, { value: "toronto", text: "Toronto", region: "Americas" }
|
|
43
|
+
];
|
|
44
|
+
const groupStatus = status("Choose one or more offices.");
|
|
45
|
+
const people = [
|
|
46
|
+
{ value: "maya", text: "Maya Chen", initials: "MC", role: "Product designer" },
|
|
47
|
+
{ value: "alex", text: "Alex Morgan", initials: "AM", role: "Frontend engineer" },
|
|
48
|
+
{ value: "sam", text: "Sam Rivera", initials: "SR", role: "Accessibility specialist" },
|
|
49
|
+
{ value: "jules", text: "Jules Martin", initials: "JM", role: "Product manager" }
|
|
50
|
+
];
|
|
51
|
+
const memberStatus = status("Selected Maya Chen.");
|
|
52
|
+
const member = new SelectComponent({
|
|
53
|
+
id: "select-owner", data: people, value: "maya",
|
|
54
|
+
ariaLabel: "Project owner", placeholder: "Assign an owner", rowHeight: 56,
|
|
55
|
+
matchSearch: (item, term) => (item.text + " " + item.role).toLowerCase().includes(term.toLowerCase()),
|
|
56
|
+
onRender: args => args.isCurrent ? text("span", args.data.text) : group([
|
|
57
|
+
{ tag: "span", content: args.data.initials, attr: { class: "select-person-avatar", "aria-hidden": "true" } },
|
|
58
|
+
group([text("strong", args.data.text), text("span", args.data.role)], "select-person-copy")
|
|
59
|
+
], "select-person"),
|
|
60
|
+
onChange: (_value, item) => { memberStatus.content = item ? "Selected " + item.text + "." : "No owner selected."; }
|
|
61
|
+
});
|
|
62
|
+
const largeStatus = status("Search by name or jump through the list with your keyboard.");
|
|
63
|
+
const large = new SelectComponent({
|
|
64
|
+
id: "select-large", data: Array.from({ length: 10000 }, (_, i) => ({ value: i + 1, text: "Item " + ("00000" + (i + 1)).slice(-5) })),
|
|
65
|
+
value: 5000, ariaLabel: "Large list", dropdownHeight: "18rem", placeholder: "Choose an item",
|
|
66
|
+
onChange: (value, item) => { largeStatus.content = item ? "Selected " + item.text + ", key " + value : "Selection cleared."; }
|
|
67
|
+
});
|
|
68
|
+
// A pretend server: 500 customers, searched and paged with a delay.
|
|
69
|
+
const customerNames = Array.from({ length: 500 }, (_, i) => ({ value: i + 1, text: "Customer " + ("000" + (i + 1)).slice(-4) + " " + ["Alpine", "Danube", "Linz", "Graz", "Tyrol"][i % 5] }));
|
|
70
|
+
const remoteStatus = status("Open the list, type a name or scroll for more.");
|
|
71
|
+
let remoteGeneration = 0;
|
|
72
|
+
let remoteFound: typeof customerNames = [];
|
|
73
|
+
let remoteTerm = "";
|
|
74
|
+
function remoteLoad(append: boolean) {
|
|
75
|
+
const generation = ++remoteGeneration;
|
|
76
|
+
remote.setLoading(true);
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
if (generation !== remoteGeneration) { return; }
|
|
79
|
+
const matches = customerNames.filter(item => item.text.toLowerCase().includes(remoteTerm.toLowerCase()));
|
|
80
|
+
remoteFound = matches.slice(0, append ? remoteFound.length + 25 : 25);
|
|
81
|
+
remote.setData(remoteFound, remoteFound.length < matches.length);
|
|
82
|
+
remote.setLoading(false);
|
|
83
|
+
remoteStatus.content = remoteFound.length + " of " + matches.length + " matches loaded.";
|
|
84
|
+
}, 400);
|
|
85
|
+
}
|
|
86
|
+
const remote: SelectComponent = new SelectComponent({
|
|
87
|
+
id: "select-remote", data: [], ariaLabel: "Customer", placeholder: "Choose a customer", searchPlaceholder: "Search customers…",
|
|
88
|
+
onOpen: () => { if (!remoteFound.length) { remoteLoad(false); } },
|
|
89
|
+
onSearch: term => { remoteTerm = term; remoteLoad(false); },
|
|
90
|
+
onLoadMore: () => remoteLoad(true)
|
|
91
|
+
});
|
|
92
|
+
function card(id: string, number: string, title: string, description: string, children: Content[]): IJSLVNode {
|
|
93
|
+
return { tag: "article", attr: { id, class: "sample-card" }, children: [
|
|
94
|
+
group([text("span", number, "sample-number"), text("h3", title)], "card-heading"),
|
|
95
|
+
text("p", description, "card-description"), ...children
|
|
96
|
+
] };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const selectShowcase: IJSLVNode = {
|
|
100
|
+
tag: "section", attr: { id: "selects", class: "component-section", "aria-labelledby": "selects-title" }, children: [
|
|
101
|
+
group([
|
|
102
|
+
group([
|
|
103
|
+
text("p", "THE ESSENTIALS / 08", "eyebrow"),
|
|
104
|
+
{ tag: "h2", content: "Selects", attr: { id: "selects-title", class: "section-title" } },
|
|
105
|
+
text("p", "One choice or a few. Search, select, and keep the options easy to scan.", "hero-description")
|
|
106
|
+
], "hero-copy"),
|
|
107
|
+
group([
|
|
108
|
+
text("span", "INTERACTIVE PREVIEW", "preview-caption"),
|
|
109
|
+
field("select-preview-single", "Project", new SelectComponent({
|
|
110
|
+
id: "select-preview-single", data: projects, value: "library", ariaLabel: "Preview project"
|
|
111
|
+
})),
|
|
112
|
+
field("select-preview-multi", "Skills", new SelectComponent({
|
|
113
|
+
id: "select-preview-multi", data: skills, multiple: true, value: ["design", "typescript"], ariaLabel: "Preview skills"
|
|
114
|
+
}))
|
|
115
|
+
], "hero-preview select-hero-preview")
|
|
116
|
+
], "hero"),
|
|
117
|
+
group([
|
|
118
|
+
text("span", "Overview", "overview-label"), text("span", "Single & multiple", "overview-stat"),
|
|
119
|
+
text("span", "Search & groups", "overview-stat"), text("span", "Keyboard accessible", "overview-stat")
|
|
120
|
+
], "overview-bar"),
|
|
121
|
+
group([
|
|
122
|
+
card("select-single", "01", "A single choice", "A searchable list with a clear selection. Choose a project, then clear it to start again.", [
|
|
123
|
+
field("select-project", "Project", single), singleStatus,
|
|
124
|
+
text("pre", '{ data: projects, placeholder: "Choose a project" }', "sample-code")
|
|
125
|
+
]),
|
|
126
|
+
card("select-multiple", "02", "A collection of choices", "Selected items become compact chips. Toggle checked options while keeping the list open.", [
|
|
127
|
+
field("select-skills", "Skills", multi), multiStatus,
|
|
128
|
+
text("p", "Enter toggles the focused option. Escape finishes and returns focus to the field.", "inline-note"),
|
|
129
|
+
text("pre", '{ multiple: true, value: ["design", "typescript"] }', "sample-code")
|
|
130
|
+
]),
|
|
131
|
+
card("select-grouped", "03", "Options with context", "Group related options. Search filters the items and preserves their headings.", [
|
|
132
|
+
field("select-offices", "Offices", new SelectComponent({
|
|
133
|
+
id: "select-offices", data: locations, groupProperty: "region", multiple: true,
|
|
134
|
+
ariaLabel: "Offices", placeholder: "Choose offices",
|
|
135
|
+
onChange: values => { groupStatus.content = values.length ? values.length + " offices selected." : "Choose one or more offices."; }
|
|
136
|
+
})), groupStatus,
|
|
137
|
+
action("Try inside a dialog", () => {
|
|
138
|
+
DialogComponent.show({
|
|
139
|
+
header: "Choose a project", width: "28rem",
|
|
140
|
+
content: group([
|
|
141
|
+
text("p", "Select a project. Escape closes the options first.", "card-description"),
|
|
142
|
+
field("select-dialog-project", "Project", new SelectComponent({
|
|
143
|
+
id: "select-dialog-project", data: projects, ariaLabel: "Dialog project", placeholder: "Choose a project"
|
|
144
|
+
}))
|
|
145
|
+
]),
|
|
146
|
+
footer: group([DialogComponent.Cancel(), DialogComponent.Ok()], "sample-row")
|
|
147
|
+
});
|
|
148
|
+
})
|
|
149
|
+
]),
|
|
150
|
+
card("select-custom", "04", "More than a label", "Custom rows add useful details about each person.", [
|
|
151
|
+
field("select-owner", "Project owner", member), memberStatus,
|
|
152
|
+
text("p", "Search also matches each person's role.", "inline-note")
|
|
153
|
+
]),
|
|
154
|
+
card("select-states", "05", "The right level of choice", "Search can be omitted for short lists. Required selections and disabled controls share the same design.", [
|
|
155
|
+
field("select-required", "Default project", new SelectComponent({
|
|
156
|
+
id: "select-required", data: projects.slice(0, 3), value: "library", ariaLabel: "Default project",
|
|
157
|
+
enableSearch: false, allowEmpty: false
|
|
158
|
+
})),
|
|
159
|
+
field("select-disabled", "Unavailable project", new SelectComponent({
|
|
160
|
+
id: "select-disabled", data: projects, value: "website", enabled: false, ariaLabel: "Unavailable project"
|
|
161
|
+
})),
|
|
162
|
+
field("select-disabled-multi", "Unavailable skills", new SelectComponent({
|
|
163
|
+
id: "select-disabled-multi", data: skills, multiple: true, value: ["design", "testing"], enabled: false, ariaLabel: "Unavailable skills"
|
|
164
|
+
}))
|
|
165
|
+
]),
|
|
166
|
+
card("select-scale", "06", "Room for a long list", "Ten thousand options, with only the visible rows rendered. Selection stays in view when you open the list.", [
|
|
167
|
+
field("select-large", "Item", large), largeStatus,
|
|
168
|
+
text("p", "Type to search. Arrow keys move through results; Ctrl+Home and Ctrl+End jump to either end.", "inline-note")
|
|
169
|
+
]),
|
|
170
|
+
card("select-server", "07", "Search on the server", "For lists too long to load. The one search box asks the server, and scrolling to the end loads more.", [
|
|
171
|
+
field("select-remote", "Customer", remote), remoteStatus,
|
|
172
|
+
text("pre", '{ onSearch: term => load(term), onLoadMore: () => loadMore() } // answer with select.setData(items, hasMore)', "sample-code")
|
|
173
|
+
])
|
|
174
|
+
], "sample-grid select-sample-grid"),
|
|
175
|
+
{ tag: "details", attr: { class: "usage" }, children: [
|
|
176
|
+
text("summary", "Select usage & compatibility"),
|
|
177
|
+
text("pre", 'new SelectComponent({\n data: [{ value: "design", text: "Design" }, { value: "code", text: "Code" }],\n multiple: true,\n value: ["design"],\n placeholder: "Choose skills",\n ariaLabel: "Skills",\n onChange: (keys, items) => console.log(keys, items)\n});', "sample-code"),
|
|
178
|
+
text("p", "Existing data, keyColumn, textColumn, grouping, render callbacks, converters, popup sizing, and onAppend options remain available. The original placehoder spelling remains supported; placeholder takes precedence. Optional id, ariaLabel, ariaLabelledBy, searchPlaceholder, emptyText, and clearButtonLabel help label and translate the control."),
|
|
179
|
+
text("p", "getValue() returns a key or an array of keys. getSelected() returns the corresponding item or items. setValue() updates the selection silently; setSelected() also raises onChange. toggle(), show(), close(), focus(), isExpanded(), and destroy() are retained. Unmounting cleans up the owning popup."),
|
|
180
|
+
text("p", "Arrow Down, Arrow Up, Enter, and Space open the list. Type to search, use arrow keys to navigate, and Enter to select. Multi-select stays open as options are toggled. Escape returns to the field; Tab continues to the next control. In a list without search, Home/End jump to the ends and Space toggles an option. With search, use Ctrl+Home/End."),
|
|
181
|
+
text("p", "The default multi-select display shows up to three chips and a count for additional items. Custom onRender callbacks still receive the full selected array when isCurrent is true. Keep custom row content decorative; selection is handled by the option itself.")
|
|
182
|
+
] }
|
|
183
|
+
]
|
|
184
|
+
};
|