decantr 0.9.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/AGENTS.md +868 -0
- package/CHANGELOG.md +255 -0
- package/CLAUDE.md +178 -0
- package/LICENSE +21 -0
- package/README.md +229 -0
- package/cli/art.js +127 -0
- package/cli/commands/a11y.js +61 -0
- package/cli/commands/audit.js +225 -0
- package/cli/commands/build.js +38 -0
- package/cli/commands/dev.js +18 -0
- package/cli/commands/doctor.js +197 -0
- package/cli/commands/figma-sync.js +48 -0
- package/cli/commands/figma-tokens.js +55 -0
- package/cli/commands/generate.js +26 -0
- package/cli/commands/init.js +116 -0
- package/cli/commands/lint.js +209 -0
- package/cli/commands/mcp.js +530 -0
- package/cli/commands/migrate.js +175 -0
- package/cli/commands/test.js +38 -0
- package/cli/commands/validate.js +354 -0
- package/cli/index.js +113 -0
- package/package.json +95 -0
- package/reference/atoms.md +517 -0
- package/reference/behaviors.md +384 -0
- package/reference/build-tooling.md +275 -0
- package/reference/color-guidelines.md +965 -0
- package/reference/component-lifecycle.md +137 -0
- package/reference/compound-spacing.md +95 -0
- package/reference/decantation-process.md +499 -0
- package/reference/dev-server-routes.md +93 -0
- package/reference/form-system.md +253 -0
- package/reference/i18n.md +336 -0
- package/reference/icons.md +576 -0
- package/reference/llm-primer.md +953 -0
- package/reference/plugins.md +252 -0
- package/reference/registry-consumption.md +76 -0
- package/reference/router.md +217 -0
- package/reference/shells.md +116 -0
- package/reference/spatial-guidelines.md +541 -0
- package/reference/ssr.md +234 -0
- package/reference/state-data.md +215 -0
- package/reference/state-patterns.md +166 -0
- package/reference/state.md +194 -0
- package/reference/style-system.md +110 -0
- package/reference/tokens.md +460 -0
- package/src/app.js +19 -0
- package/src/chart/_animate.js +266 -0
- package/src/chart/_base.js +109 -0
- package/src/chart/_data.js +209 -0
- package/src/chart/_format.js +106 -0
- package/src/chart/_interact.js +364 -0
- package/src/chart/_palette.js +105 -0
- package/src/chart/_renderer.js +52 -0
- package/src/chart/_scene.js +262 -0
- package/src/chart/_shared.js +371 -0
- package/src/chart/index.js +637 -0
- package/src/chart/layouts/_layout-base.js +328 -0
- package/src/chart/layouts/cartesian.js +148 -0
- package/src/chart/layouts/hierarchy.js +562 -0
- package/src/chart/layouts/polar.js +101 -0
- package/src/chart/renderers/canvas.js +179 -0
- package/src/chart/renderers/svg.js +256 -0
- package/src/chart/renderers/webgpu.js +715 -0
- package/src/chart/types/_type-base.js +26 -0
- package/src/chart/types/area.js +134 -0
- package/src/chart/types/bar.js +173 -0
- package/src/chart/types/box-plot.js +125 -0
- package/src/chart/types/bubble.js +63 -0
- package/src/chart/types/candlestick.js +115 -0
- package/src/chart/types/chord.js +85 -0
- package/src/chart/types/combination.js +108 -0
- package/src/chart/types/funnel.js +68 -0
- package/src/chart/types/gauge.js +163 -0
- package/src/chart/types/heatmap.js +98 -0
- package/src/chart/types/histogram.js +71 -0
- package/src/chart/types/line.js +111 -0
- package/src/chart/types/org-chart.js +93 -0
- package/src/chart/types/pie.js +81 -0
- package/src/chart/types/radar.js +96 -0
- package/src/chart/types/radial.js +68 -0
- package/src/chart/types/range-area.js +55 -0
- package/src/chart/types/range-bar.js +61 -0
- package/src/chart/types/sankey.js +73 -0
- package/src/chart/types/scatter.js +66 -0
- package/src/chart/types/sparkline.js +81 -0
- package/src/chart/types/sunburst.js +69 -0
- package/src/chart/types/swimlane.js +88 -0
- package/src/chart/types/treemap.js +62 -0
- package/src/chart/types/waterfall.js +100 -0
- package/src/components/_base.js +1658 -0
- package/src/components/_behaviors.js +1140 -0
- package/src/components/_primitives.js +534 -0
- package/src/components/_qr-encoder.js +539 -0
- package/src/components/accordion.js +207 -0
- package/src/components/affix.js +62 -0
- package/src/components/alert-dialog.js +75 -0
- package/src/components/alert.js +47 -0
- package/src/components/aspect-ratio.js +24 -0
- package/src/components/avatar-group.js +55 -0
- package/src/components/avatar.js +38 -0
- package/src/components/back-top.js +75 -0
- package/src/components/badge.js +74 -0
- package/src/components/banner.js +68 -0
- package/src/components/breadcrumb.js +162 -0
- package/src/components/button.js +115 -0
- package/src/components/calendar.js +131 -0
- package/src/components/card.js +192 -0
- package/src/components/carousel.js +98 -0
- package/src/components/cascader.js +261 -0
- package/src/components/checkbox.js +80 -0
- package/src/components/chip.js +81 -0
- package/src/components/code-block.js +82 -0
- package/src/components/collapsible.js +50 -0
- package/src/components/color-palette.js +438 -0
- package/src/components/color-picker.js +314 -0
- package/src/components/combobox.js +181 -0
- package/src/components/command.js +174 -0
- package/src/components/comment.js +206 -0
- package/src/components/context-menu.js +76 -0
- package/src/components/data-table.js +724 -0
- package/src/components/date-picker.js +217 -0
- package/src/components/date-range-picker.js +244 -0
- package/src/components/datetime-picker.js +271 -0
- package/src/components/descriptions.js +68 -0
- package/src/components/drawer.js +179 -0
- package/src/components/dropdown.js +88 -0
- package/src/components/empty.js +41 -0
- package/src/components/float-button.js +90 -0
- package/src/components/form.js +106 -0
- package/src/components/hover-card.js +49 -0
- package/src/components/icon.js +87 -0
- package/src/components/image.js +97 -0
- package/src/components/index.js +117 -0
- package/src/components/input-group.js +75 -0
- package/src/components/input-number.js +155 -0
- package/src/components/input-otp.js +178 -0
- package/src/components/input.js +91 -0
- package/src/components/kbd.js +36 -0
- package/src/components/label.js +25 -0
- package/src/components/list.js +118 -0
- package/src/components/masked-input.js +236 -0
- package/src/components/mentions.js +165 -0
- package/src/components/menu.js +259 -0
- package/src/components/message.js +80 -0
- package/src/components/modal.js +147 -0
- package/src/components/navigation-menu.js +166 -0
- package/src/components/notification.js +84 -0
- package/src/components/pagination.js +104 -0
- package/src/components/placeholder.js +132 -0
- package/src/components/popconfirm.js +70 -0
- package/src/components/popover.js +58 -0
- package/src/components/progress.js +61 -0
- package/src/components/qrcode.js +251 -0
- package/src/components/radiogroup.js +120 -0
- package/src/components/range-slider.js +176 -0
- package/src/components/rate.js +186 -0
- package/src/components/resizable.js +83 -0
- package/src/components/result.js +57 -0
- package/src/components/scroll-area.js +43 -0
- package/src/components/segmented.js +97 -0
- package/src/components/select.js +165 -0
- package/src/components/separator.js +31 -0
- package/src/components/shell.js +407 -0
- package/src/components/skeleton.js +39 -0
- package/src/components/slider.js +141 -0
- package/src/components/sortable-list.js +176 -0
- package/src/components/space.js +42 -0
- package/src/components/spinner.js +112 -0
- package/src/components/splitter.js +147 -0
- package/src/components/statistic.js +136 -0
- package/src/components/steps.js +99 -0
- package/src/components/switch.js +95 -0
- package/src/components/table.js +44 -0
- package/src/components/tabs.js +216 -0
- package/src/components/tag.js +115 -0
- package/src/components/textarea.js +82 -0
- package/src/components/time-picker.js +153 -0
- package/src/components/time-range-picker.js +170 -0
- package/src/components/timeline.js +226 -0
- package/src/components/toast.js +71 -0
- package/src/components/toggle.js +213 -0
- package/src/components/tooltip.js +57 -0
- package/src/components/tour.js +159 -0
- package/src/components/transfer.js +163 -0
- package/src/components/tree-select.js +274 -0
- package/src/components/tree.js +141 -0
- package/src/components/typography.js +136 -0
- package/src/components/upload.js +118 -0
- package/src/components/visually-hidden.js +20 -0
- package/src/components/watermark.js +124 -0
- package/src/core/index.js +539 -0
- package/src/core/lifecycle.js +69 -0
- package/src/css/atoms.js +651 -0
- package/src/css/components.js +940 -0
- package/src/css/derive.js +1296 -0
- package/src/css/index.js +265 -0
- package/src/css/runtime.js +268 -0
- package/src/css/styles/addons/bioluminescent.js +93 -0
- package/src/css/styles/addons/clay.js +70 -0
- package/src/css/styles/addons/clean.js +57 -0
- package/src/css/styles/addons/command-center.js +143 -0
- package/src/css/styles/addons/dopamine.js +83 -0
- package/src/css/styles/addons/editorial.js +80 -0
- package/src/css/styles/addons/glassmorphism.js +99 -0
- package/src/css/styles/addons/liquid-glass.js +105 -0
- package/src/css/styles/addons/prismatic.js +100 -0
- package/src/css/styles/addons/retro.js +63 -0
- package/src/css/styles/auradecantism.js +96 -0
- package/src/css/theme-registry.js +444 -0
- package/src/data/entity.js +281 -0
- package/src/data/index.js +13 -0
- package/src/data/persist.js +225 -0
- package/src/data/query.js +839 -0
- package/src/data/realtime.js +299 -0
- package/src/data/url.js +177 -0
- package/src/data/worker.js +134 -0
- package/src/explorer/archetypes.js +243 -0
- package/src/explorer/atoms.js +228 -0
- package/src/explorer/charts.js +497 -0
- package/src/explorer/components.js +129 -0
- package/src/explorer/foundations.js +949 -0
- package/src/explorer/icons.js +178 -0
- package/src/explorer/patterns.js +247 -0
- package/src/explorer/recipes.js +194 -0
- package/src/explorer/shared/pattern-examples.js +1337 -0
- package/src/explorer/shared/showcase-renderer.js +958 -0
- package/src/explorer/shared/spec-table.js +41 -0
- package/src/explorer/shared/usage-links.js +87 -0
- package/src/explorer/shell-config.js +10 -0
- package/src/explorer/shells.js +551 -0
- package/src/explorer/styles.js +161 -0
- package/src/explorer/tokens.js +262 -0
- package/src/explorer/tools.js +525 -0
- package/src/form/index.js +804 -0
- package/src/i18n/index.js +251 -0
- package/src/icons/essential.js +479 -0
- package/src/icons/index.js +53 -0
- package/src/plugins/index.js +282 -0
- package/src/registry/archetypes/content-site.json +71 -0
- package/src/registry/archetypes/docs-explorer.json +23 -0
- package/src/registry/archetypes/ecommerce.json +104 -0
- package/src/registry/archetypes/financial-dashboard.json +77 -0
- package/src/registry/archetypes/index.json +41 -0
- package/src/registry/archetypes/portfolio.json +82 -0
- package/src/registry/archetypes/recipe-community.json +159 -0
- package/src/registry/archetypes/saas-dashboard.json +86 -0
- package/src/registry/architect/cross-cutting.json +45 -0
- package/src/registry/architect/domains/ecommerce.json +294 -0
- package/src/registry/architect/domains/financial-services.json +302 -0
- package/src/registry/architect/index.json +26 -0
- package/src/registry/architect/traits.json +379 -0
- package/src/registry/atoms.json +16 -0
- package/src/registry/chart-showcase.json +160 -0
- package/src/registry/chart.json +136 -0
- package/src/registry/components.json +8616 -0
- package/src/registry/core.json +216 -0
- package/src/registry/css.json +319 -0
- package/src/registry/data.json +135 -0
- package/src/registry/foundations.json +11 -0
- package/src/registry/icons.json +463 -0
- package/src/registry/index.json +101 -0
- package/src/registry/patterns/activity-feed.json +37 -0
- package/src/registry/patterns/article-content.json +27 -0
- package/src/registry/patterns/auth-form.json +37 -0
- package/src/registry/patterns/author-card.json +20 -0
- package/src/registry/patterns/card-grid.json +127 -0
- package/src/registry/patterns/category-nav.json +26 -0
- package/src/registry/patterns/chart-grid.json +36 -0
- package/src/registry/patterns/chat-interface.json +37 -0
- package/src/registry/patterns/checklist-card.json +55 -0
- package/src/registry/patterns/comparison-panel.json +27 -0
- package/src/registry/patterns/component-showcase.json +24 -0
- package/src/registry/patterns/contact-form.json +31 -0
- package/src/registry/patterns/cta-section.json +20 -0
- package/src/registry/patterns/data-table.json +37 -0
- package/src/registry/patterns/detail-header.json +83 -0
- package/src/registry/patterns/detail-panel.json +27 -0
- package/src/registry/patterns/explorer-shell.json +22 -0
- package/src/registry/patterns/filter-bar.json +33 -0
- package/src/registry/patterns/filter-sidebar.json +27 -0
- package/src/registry/patterns/form-sections.json +110 -0
- package/src/registry/patterns/goal-tracker.json +27 -0
- package/src/registry/patterns/hero.json +107 -0
- package/src/registry/patterns/index.json +47 -0
- package/src/registry/patterns/kpi-grid.json +36 -0
- package/src/registry/patterns/media-gallery.json +20 -0
- package/src/registry/patterns/order-history.json +20 -0
- package/src/registry/patterns/pagination.json +19 -0
- package/src/registry/patterns/photo-to-recipe.json +36 -0
- package/src/registry/patterns/pipeline-tracker.json +28 -0
- package/src/registry/patterns/post-list.json +27 -0
- package/src/registry/patterns/pricing-table.json +32 -0
- package/src/registry/patterns/scorecard.json +28 -0
- package/src/registry/patterns/search-bar.json +20 -0
- package/src/registry/patterns/specimen-grid.json +19 -0
- package/src/registry/patterns/stat-card.json +55 -0
- package/src/registry/patterns/stats-bar.json +55 -0
- package/src/registry/patterns/steps-card.json +55 -0
- package/src/registry/patterns/table-of-contents.json +19 -0
- package/src/registry/patterns/testimonials.json +21 -0
- package/src/registry/patterns/timeline.json +27 -0
- package/src/registry/patterns/token-inspector.json +21 -0
- package/src/registry/patterns/wizard.json +27 -0
- package/src/registry/recipe-auradecantism.json +69 -0
- package/src/registry/recipe-clean.json +65 -0
- package/src/registry/recipe-command-center.json +78 -0
- package/src/registry/router.json +73 -0
- package/src/registry/schema/README.md +197 -0
- package/src/registry/skeletons.json +259 -0
- package/src/registry/state.json +137 -0
- package/src/registry/tokens.json +40 -0
- package/src/router/hash.js +17 -0
- package/src/router/history.js +18 -0
- package/src/router/index.js +598 -0
- package/src/ssr/index.js +922 -0
- package/src/state/arrays.js +181 -0
- package/src/state/devtools.js +647 -0
- package/src/state/index.js +498 -0
- package/src/state/middleware.js +288 -0
- package/src/state/scheduler.js +206 -0
- package/src/state/store.js +300 -0
- package/src/tags/index.js +19 -0
- package/src/tannins/auth.js +396 -0
- package/src/test/dom.js +352 -0
- package/src/test/index.js +62 -0
- package/src/test/state.js +306 -0
- package/tools/a11y-audit.js +487 -0
- package/tools/analyzer.js +315 -0
- package/tools/audit.js +706 -0
- package/tools/builder.js +1422 -0
- package/tools/css-extract.js +188 -0
- package/tools/dev-server.js +316 -0
- package/tools/dts-gen.js +1260 -0
- package/tools/figma-components.js +329 -0
- package/tools/figma-patterns.js +516 -0
- package/tools/figma-plugin/code.js +453 -0
- package/tools/figma-plugin/manifest.json +14 -0
- package/tools/figma-plugin/ui.html +268 -0
- package/tools/figma-render.js +293 -0
- package/tools/figma-tokens.js +712 -0
- package/tools/figma-upload.js +318 -0
- package/tools/generate.js +738 -0
- package/tools/icons.js +133 -0
- package/tools/init-templates.js +265 -0
- package/tools/install-hooks.sh +5 -0
- package/tools/migrations/0.5.0.js +53 -0
- package/tools/migrations/0.6.0.js +95 -0
- package/tools/minify.js +170 -0
- package/tools/pre-commit +4 -0
- package/tools/registry.js +662 -0
- package/tools/reset-playground.js +61 -0
- package/tools/starter-templates/content-site/app.js +49 -0
- package/tools/starter-templates/content-site/essence.js +19 -0
- package/tools/starter-templates/content-site/pages.js +31 -0
- package/tools/starter-templates/ecommerce/app.js +50 -0
- package/tools/starter-templates/ecommerce/essence.js +19 -0
- package/tools/starter-templates/ecommerce/pages.js +31 -0
- package/tools/starter-templates/landing-page/app.js +38 -0
- package/tools/starter-templates/landing-page/essence.js +18 -0
- package/tools/starter-templates/landing-page/pages.js +21 -0
- package/tools/starter-templates/portfolio/app.js +45 -0
- package/tools/starter-templates/portfolio/essence.js +19 -0
- package/tools/starter-templates/portfolio/pages.js +33 -0
- package/tools/starter-templates/saas-dashboard/app.js +70 -0
- package/tools/starter-templates/saas-dashboard/essence.js +19 -0
- package/tools/starter-templates/saas-dashboard/pages.js +31 -0
- package/tools/verify-pack.js +203 -0
- package/types/chart.d.ts +77 -0
- package/types/components.d.ts +587 -0
- package/types/core.d.ts +89 -0
- package/types/css.d.ts +149 -0
- package/types/data.d.ts +238 -0
- package/types/form.d.ts +164 -0
- package/types/i18n.d.ts +51 -0
- package/types/icons.d.ts +27 -0
- package/types/index.d.ts +13 -0
- package/types/router.d.ts +116 -0
- package/types/ssr.d.ts +102 -0
- package/types/state.d.ts +83 -0
- package/types/tags.d.ts +62 -0
- package/types/tannins.d.ts +63 -0
- package/types/test.d.ts +48 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { createEffect } from '../state/index.js';
|
|
2
|
+
import { tags } from '../tags/index.js';
|
|
3
|
+
import { injectBase, cx } from './_base.js';
|
|
4
|
+
import { createRovingTabindex } from './_behaviors.js';
|
|
5
|
+
|
|
6
|
+
const { div, label: labelTag, input: inputTag, span } = tags;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {Object} [props]
|
|
10
|
+
* @param {{ value: string, label: string, disabled?: boolean }[]} props.options
|
|
11
|
+
* @param {string|Function} [props.value]
|
|
12
|
+
* @param {string} [props.name]
|
|
13
|
+
* @param {boolean|Function} [props.disabled]
|
|
14
|
+
* @param {string} [props.orientation='vertical'] - 'vertical'|'horizontal'
|
|
15
|
+
* @param {boolean|string|Function} [props.error]
|
|
16
|
+
* @param {string} [props.size] - xs|sm|lg
|
|
17
|
+
* @param {Function} [props.onchange]
|
|
18
|
+
* @param {string} [props['aria-label']]
|
|
19
|
+
* @param {string} [props.class]
|
|
20
|
+
* @returns {HTMLElement}
|
|
21
|
+
*/
|
|
22
|
+
export function RadioGroup(props = {}) {
|
|
23
|
+
injectBase();
|
|
24
|
+
|
|
25
|
+
const {
|
|
26
|
+
options = [], value, name = `d-radio-${Date.now()}`,
|
|
27
|
+
disabled, orientation = 'vertical', error, size, onchange,
|
|
28
|
+
'aria-label': ariaLabel, class: cls
|
|
29
|
+
} = props;
|
|
30
|
+
|
|
31
|
+
let currentValue = typeof value === 'function' ? value() : (value || '');
|
|
32
|
+
|
|
33
|
+
const groupProps = {
|
|
34
|
+
class: cx('d-radiogroup', orientation === 'horizontal' && 'd-radiogroup-horizontal', size && `d-radiogroup-${size}`, cls),
|
|
35
|
+
role: 'radiogroup'
|
|
36
|
+
};
|
|
37
|
+
if (ariaLabel) groupProps['aria-label'] = ariaLabel;
|
|
38
|
+
|
|
39
|
+
const group = div(groupProps);
|
|
40
|
+
const radios = [];
|
|
41
|
+
|
|
42
|
+
options.forEach((opt) => {
|
|
43
|
+
const native = inputTag({
|
|
44
|
+
type: 'radio',
|
|
45
|
+
name,
|
|
46
|
+
value: opt.value,
|
|
47
|
+
class: 'd-radio-native',
|
|
48
|
+
'aria-label': opt.label
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (opt.value === currentValue) native.checked = true;
|
|
52
|
+
if (opt.disabled) native.disabled = true;
|
|
53
|
+
|
|
54
|
+
const indicator = span({ class: 'd-radio-indicator' }, span({ class: 'd-radio-dot' }));
|
|
55
|
+
const label = span({ class: 'd-radio-label' }, opt.label);
|
|
56
|
+
|
|
57
|
+
const wrapper = labelTag({
|
|
58
|
+
class: cx('d-radio', opt.disabled && 'd-radio-disabled')
|
|
59
|
+
}, native, indicator, label);
|
|
60
|
+
|
|
61
|
+
native.addEventListener('change', () => {
|
|
62
|
+
if (native.checked) {
|
|
63
|
+
currentValue = opt.value;
|
|
64
|
+
updateChecked();
|
|
65
|
+
if (onchange) onchange(opt.value);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
radios.push({ native, wrapper, opt });
|
|
70
|
+
group.appendChild(wrapper);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
function updateChecked() {
|
|
74
|
+
radios.forEach(({ native, opt }) => {
|
|
75
|
+
native.checked = opt.value === currentValue;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Use createRovingTabindex for keyboard navigation
|
|
80
|
+
createRovingTabindex(group, {
|
|
81
|
+
itemSelector: '.d-radio-native:not([disabled])',
|
|
82
|
+
orientation: orientation === 'horizontal' ? 'horizontal' : 'vertical',
|
|
83
|
+
onFocus: (el) => {
|
|
84
|
+
el.checked = true;
|
|
85
|
+
el.dispatchEvent(new Event('change'));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Reactive value
|
|
90
|
+
if (typeof value === 'function') {
|
|
91
|
+
createEffect(() => {
|
|
92
|
+
currentValue = value();
|
|
93
|
+
updateChecked();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Reactive disabled
|
|
98
|
+
if (typeof disabled === 'function') {
|
|
99
|
+
createEffect(() => {
|
|
100
|
+
const v = disabled();
|
|
101
|
+
radios.forEach(({ native }) => { native.disabled = v; });
|
|
102
|
+
group.toggleAttribute('data-disabled', v);
|
|
103
|
+
});
|
|
104
|
+
} else if (disabled) {
|
|
105
|
+
radios.forEach(({ native }) => { native.disabled = true; });
|
|
106
|
+
group.setAttribute('data-disabled', '');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Reactive error
|
|
110
|
+
if (typeof error === 'function') {
|
|
111
|
+
createEffect(() => {
|
|
112
|
+
const v = error();
|
|
113
|
+
group.toggleAttribute('data-error', !!v);
|
|
114
|
+
});
|
|
115
|
+
} else if (error) {
|
|
116
|
+
group.setAttribute('data-error', '');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return group;
|
|
120
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RangeSlider — Dual-thumb slider for selecting a numeric range.
|
|
3
|
+
* Keyboard accessible with ARIA slider pattern.
|
|
4
|
+
* Uses createDrag behavior for pointer interaction.
|
|
5
|
+
*
|
|
6
|
+
* @module decantr/components/range-slider
|
|
7
|
+
*/
|
|
8
|
+
import { h } from '../core/index.js';
|
|
9
|
+
import { createEffect } from '../state/index.js';
|
|
10
|
+
import { injectBase, cx } from './_base.js';
|
|
11
|
+
import { createDrag } from './_behaviors.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {Object} [props]
|
|
15
|
+
* @param {Array<number>|Function} [props.value] - [min, max]
|
|
16
|
+
* @param {number} [props.min=0]
|
|
17
|
+
* @param {number} [props.max=100]
|
|
18
|
+
* @param {number} [props.step=1]
|
|
19
|
+
* @param {Function} [props.onchange] - ([low, high]) => void
|
|
20
|
+
* @param {boolean|Function} [props.disabled]
|
|
21
|
+
* @param {string} [props.class]
|
|
22
|
+
* @returns {HTMLElement}
|
|
23
|
+
*/
|
|
24
|
+
export function RangeSlider(props = {}) {
|
|
25
|
+
injectBase();
|
|
26
|
+
const {
|
|
27
|
+
value, min: pMin = 0, max: pMax = 100, step = 1,
|
|
28
|
+
onchange, disabled, class: cls
|
|
29
|
+
} = props;
|
|
30
|
+
|
|
31
|
+
let low = pMin;
|
|
32
|
+
let high = pMax;
|
|
33
|
+
|
|
34
|
+
function parseValue(v) {
|
|
35
|
+
if (!v || !Array.isArray(v)) return;
|
|
36
|
+
low = clamp(v[0] ?? pMin);
|
|
37
|
+
high = clamp(v[1] ?? pMax);
|
|
38
|
+
if (low > high) { const t = low; low = high; high = t; }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function clamp(v) {
|
|
42
|
+
return Math.min(pMax, Math.max(pMin, Math.round(v / step) * step));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function pct(v) {
|
|
46
|
+
return ((v - pMin) / (pMax - pMin)) * 100;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
parseValue(typeof value === 'function' ? value() : value);
|
|
50
|
+
|
|
51
|
+
const track = h('div', { class: 'd-rangeslider-track' });
|
|
52
|
+
const fill = h('div', { class: 'd-rangeslider-fill' });
|
|
53
|
+
|
|
54
|
+
const thumbLow = h('div', {
|
|
55
|
+
class: 'd-rangeslider-thumb',
|
|
56
|
+
role: 'slider',
|
|
57
|
+
tabindex: '0',
|
|
58
|
+
'aria-valuemin': String(pMin),
|
|
59
|
+
'aria-valuemax': String(pMax),
|
|
60
|
+
'aria-valuenow': String(low),
|
|
61
|
+
'aria-label': 'Range start'
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const thumbHigh = h('div', {
|
|
65
|
+
class: 'd-rangeslider-thumb',
|
|
66
|
+
role: 'slider',
|
|
67
|
+
tabindex: '0',
|
|
68
|
+
'aria-valuemin': String(pMin),
|
|
69
|
+
'aria-valuemax': String(pMax),
|
|
70
|
+
'aria-valuenow': String(high),
|
|
71
|
+
'aria-label': 'Range end'
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const container = h('div', {
|
|
75
|
+
class: cx('d-rangeslider', cls),
|
|
76
|
+
role: 'group',
|
|
77
|
+
'aria-label': 'Range slider'
|
|
78
|
+
}, track, fill, thumbLow, thumbHigh);
|
|
79
|
+
|
|
80
|
+
function syncDOM() {
|
|
81
|
+
const lp = pct(low);
|
|
82
|
+
const hp = pct(high);
|
|
83
|
+
thumbLow.style.left = lp + '%';
|
|
84
|
+
thumbHigh.style.left = hp + '%';
|
|
85
|
+
fill.style.left = lp + '%';
|
|
86
|
+
fill.style.width = (hp - lp) + '%';
|
|
87
|
+
thumbLow.setAttribute('aria-valuenow', String(low));
|
|
88
|
+
thumbHigh.setAttribute('aria-valuenow', String(high));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function emit() {
|
|
92
|
+
if (onchange) onchange([low, high]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function valueFromX(clientX) {
|
|
96
|
+
const rect = container.getBoundingClientRect();
|
|
97
|
+
const ratio = (clientX - rect.left) / rect.width;
|
|
98
|
+
return clamp(pMin + ratio * (pMax - pMin));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Drag for low thumb
|
|
102
|
+
createDrag(thumbLow, {
|
|
103
|
+
onMove: (x) => {
|
|
104
|
+
const v = valueFromX(x);
|
|
105
|
+
if (v <= high) { low = v; } else { low = high; high = v; }
|
|
106
|
+
syncDOM();
|
|
107
|
+
},
|
|
108
|
+
onEnd: () => emit()
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Drag for high thumb
|
|
112
|
+
createDrag(thumbHigh, {
|
|
113
|
+
onMove: (x) => {
|
|
114
|
+
const v = valueFromX(x);
|
|
115
|
+
if (v >= low) { high = v; } else { high = low; low = v; }
|
|
116
|
+
syncDOM();
|
|
117
|
+
},
|
|
118
|
+
onEnd: () => emit()
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Click on track to move nearest thumb
|
|
122
|
+
container.addEventListener('pointerdown', (e) => {
|
|
123
|
+
if (e.target === thumbLow || e.target === thumbHigh) return;
|
|
124
|
+
const v = valueFromX(e.clientX);
|
|
125
|
+
if (Math.abs(v - low) <= Math.abs(v - high)) {
|
|
126
|
+
low = v;
|
|
127
|
+
thumbLow.focus();
|
|
128
|
+
} else {
|
|
129
|
+
high = v;
|
|
130
|
+
thumbHigh.focus();
|
|
131
|
+
}
|
|
132
|
+
syncDOM();
|
|
133
|
+
emit();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Keyboard
|
|
137
|
+
function handleKey(e, isLow) {
|
|
138
|
+
let delta = 0;
|
|
139
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowUp') delta = step;
|
|
140
|
+
else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') delta = -step;
|
|
141
|
+
else if (e.key === 'Home') { delta = pMin - (isLow ? low : high); }
|
|
142
|
+
else if (e.key === 'End') { delta = pMax - (isLow ? low : high); }
|
|
143
|
+
else return;
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
if (isLow) {
|
|
146
|
+
low = clamp(low + delta);
|
|
147
|
+
if (low > high) low = high;
|
|
148
|
+
} else {
|
|
149
|
+
high = clamp(high + delta);
|
|
150
|
+
if (high < low) high = low;
|
|
151
|
+
}
|
|
152
|
+
syncDOM();
|
|
153
|
+
emit();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
thumbLow.addEventListener('keydown', (e) => handleKey(e, true));
|
|
157
|
+
thumbHigh.addEventListener('keydown', (e) => handleKey(e, false));
|
|
158
|
+
|
|
159
|
+
// Reactive disabled
|
|
160
|
+
if (typeof disabled === 'function') {
|
|
161
|
+
createEffect(() => {
|
|
162
|
+
if (disabled()) container.setAttribute('data-disabled', '');
|
|
163
|
+
else container.removeAttribute('data-disabled');
|
|
164
|
+
});
|
|
165
|
+
} else if (disabled) {
|
|
166
|
+
container.setAttribute('data-disabled', '');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Reactive value
|
|
170
|
+
if (typeof value === 'function') {
|
|
171
|
+
createEffect(() => { parseValue(value()); syncDOM(); });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
syncDOM();
|
|
175
|
+
return container;
|
|
176
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate — Star rating component.
|
|
3
|
+
* Supports half-star, custom icons, reactive value.
|
|
4
|
+
*
|
|
5
|
+
* @module decantr/components/rate
|
|
6
|
+
*/
|
|
7
|
+
import { onDestroy } from '../core/index.js';
|
|
8
|
+
import { createEffect } from '../state/index.js';
|
|
9
|
+
import { tags } from '../tags/index.js';
|
|
10
|
+
import { injectBase, cx } from './_base.js';
|
|
11
|
+
import { createFormField } from './_behaviors.js';
|
|
12
|
+
|
|
13
|
+
const { div, button: buttonTag } = tags;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {Object} [props]
|
|
17
|
+
* @param {number|Function} [props.value=0] - Current rating value
|
|
18
|
+
* @param {number} [props.count=5] - Number of stars
|
|
19
|
+
* @param {boolean} [props.half=false] - Allow half-star ratings
|
|
20
|
+
* @param {boolean|Function} [props.disabled=false]
|
|
21
|
+
* @param {boolean} [props.readonly=false]
|
|
22
|
+
* @param {string} [props.size] - sm|lg
|
|
23
|
+
* @param {string} [props.character='★'] - Star character or custom text
|
|
24
|
+
* @param {boolean|string|Function} [props.error]
|
|
25
|
+
* @param {boolean|string|Function} [props.success]
|
|
26
|
+
* @param {string} [props.label] - Label for createFormField
|
|
27
|
+
* @param {string} [props.help] - Help text for createFormField
|
|
28
|
+
* @param {boolean} [props.required] - Required indicator
|
|
29
|
+
* @param {Function} [props.onchange]
|
|
30
|
+
* @param {string} [props['aria-label']]
|
|
31
|
+
* @param {string} [props.class]
|
|
32
|
+
* @returns {HTMLElement}
|
|
33
|
+
*/
|
|
34
|
+
export function Rate(props = {}) {
|
|
35
|
+
injectBase();
|
|
36
|
+
const {
|
|
37
|
+
value = 0, count = 5, half = false, disabled = false, readonly = false,
|
|
38
|
+
size, character = '\u2605', onchange, class: cls,
|
|
39
|
+
error, success, label, help, required,
|
|
40
|
+
'aria-label': ariaLabel
|
|
41
|
+
} = props;
|
|
42
|
+
|
|
43
|
+
let current = typeof value === 'function' ? value() : value;
|
|
44
|
+
let hoverVal = -1;
|
|
45
|
+
|
|
46
|
+
const container = div({
|
|
47
|
+
class: cx('d-rate', size && `d-rate-${size}`, cls),
|
|
48
|
+
role: 'radiogroup',
|
|
49
|
+
'aria-label': ariaLabel || 'Rating',
|
|
50
|
+
'aria-disabled': (typeof disabled === 'function' ? disabled() : disabled) ? 'true' : 'false'
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// Reactive aria-disabled
|
|
54
|
+
if (typeof disabled === 'function') {
|
|
55
|
+
createEffect(() => {
|
|
56
|
+
container.setAttribute('aria-disabled', disabled() ? 'true' : 'false');
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Error state
|
|
61
|
+
if (typeof error === 'function') {
|
|
62
|
+
createEffect(() => {
|
|
63
|
+
const v = error();
|
|
64
|
+
container.toggleAttribute('data-error', !!v);
|
|
65
|
+
container.setAttribute('aria-invalid', v ? 'true' : 'false');
|
|
66
|
+
});
|
|
67
|
+
} else if (error) {
|
|
68
|
+
container.setAttribute('data-error', '');
|
|
69
|
+
container.setAttribute('aria-invalid', 'true');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Success state
|
|
73
|
+
if (typeof success === 'function') {
|
|
74
|
+
createEffect(() => { container.toggleAttribute('data-success', !!success()); });
|
|
75
|
+
} else if (success) {
|
|
76
|
+
container.setAttribute('data-success', '');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const stars = [];
|
|
80
|
+
const cleanups = [];
|
|
81
|
+
|
|
82
|
+
function isDisabled() {
|
|
83
|
+
return readonly || (typeof disabled === 'function' ? disabled() : disabled);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function updateStars() {
|
|
87
|
+
const displayVal = hoverVal >= 0 ? hoverVal : current;
|
|
88
|
+
stars.forEach((star, i) => {
|
|
89
|
+
const val = i + 1;
|
|
90
|
+
const filled = displayVal >= val;
|
|
91
|
+
const halfFilled = half && displayVal >= val - 0.5 && displayVal < val;
|
|
92
|
+
star.classList.toggle('d-rate-star-active', filled);
|
|
93
|
+
star.classList.toggle('d-rate-star-half', halfFilled && !filled);
|
|
94
|
+
star.setAttribute('aria-checked', filled || halfFilled ? 'true' : 'false');
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for (let i = 0; i < count; i++) {
|
|
99
|
+
const star = buttonTag({
|
|
100
|
+
type: 'button',
|
|
101
|
+
class: 'd-rate-star',
|
|
102
|
+
role: 'radio',
|
|
103
|
+
'aria-label': `${i + 1} star${i > 0 ? 's' : ''}`,
|
|
104
|
+
tabindex: i === 0 ? '0' : '-1'
|
|
105
|
+
}, character);
|
|
106
|
+
|
|
107
|
+
const onClick = () => {
|
|
108
|
+
if (isDisabled()) return;
|
|
109
|
+
const newVal = i + 1;
|
|
110
|
+
current = current === newVal ? 0 : newVal;
|
|
111
|
+
updateStars();
|
|
112
|
+
if (onchange) onchange(current);
|
|
113
|
+
};
|
|
114
|
+
star.addEventListener('click', onClick);
|
|
115
|
+
cleanups.push(() => star.removeEventListener('click', onClick));
|
|
116
|
+
|
|
117
|
+
if (half) {
|
|
118
|
+
const onMousemove = (e) => {
|
|
119
|
+
if (isDisabled()) return;
|
|
120
|
+
const rect = star.getBoundingClientRect();
|
|
121
|
+
hoverVal = e.clientX < rect.left + rect.width / 2 ? i + 0.5 : i + 1;
|
|
122
|
+
updateStars();
|
|
123
|
+
};
|
|
124
|
+
star.addEventListener('mousemove', onMousemove);
|
|
125
|
+
cleanups.push(() => star.removeEventListener('mousemove', onMousemove));
|
|
126
|
+
} else {
|
|
127
|
+
const onMouseenter = () => {
|
|
128
|
+
if (isDisabled()) return;
|
|
129
|
+
hoverVal = i + 1;
|
|
130
|
+
updateStars();
|
|
131
|
+
};
|
|
132
|
+
star.addEventListener('mouseenter', onMouseenter);
|
|
133
|
+
cleanups.push(() => star.removeEventListener('mouseenter', onMouseenter));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const onKeydown = (e) => {
|
|
137
|
+
if (isDisabled()) return;
|
|
138
|
+
if (e.key === 'ArrowRight' || e.key === 'ArrowUp') {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
const step = half ? 0.5 : 1;
|
|
141
|
+
current = Math.min(count, current + step);
|
|
142
|
+
updateStars();
|
|
143
|
+
if (onchange) onchange(current);
|
|
144
|
+
const next = Math.min(count - 1, i + 1);
|
|
145
|
+
stars[next].focus();
|
|
146
|
+
} else if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') {
|
|
147
|
+
e.preventDefault();
|
|
148
|
+
const step = half ? 0.5 : 1;
|
|
149
|
+
current = Math.max(0, current - step);
|
|
150
|
+
updateStars();
|
|
151
|
+
if (onchange) onchange(current);
|
|
152
|
+
const prev = Math.max(0, i - 1);
|
|
153
|
+
stars[prev].focus();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
star.addEventListener('keydown', onKeydown);
|
|
157
|
+
cleanups.push(() => star.removeEventListener('keydown', onKeydown));
|
|
158
|
+
|
|
159
|
+
stars.push(star);
|
|
160
|
+
container.appendChild(star);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const onMouseleave = () => {
|
|
164
|
+
hoverVal = -1;
|
|
165
|
+
updateStars();
|
|
166
|
+
};
|
|
167
|
+
container.addEventListener('mouseleave', onMouseleave);
|
|
168
|
+
cleanups.push(() => container.removeEventListener('mouseleave', onMouseleave));
|
|
169
|
+
|
|
170
|
+
updateStars();
|
|
171
|
+
|
|
172
|
+
if (typeof value === 'function') {
|
|
173
|
+
createEffect(() => { current = value(); updateStars(); });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Cleanup
|
|
177
|
+
onDestroy(() => { cleanups.forEach(fn => fn()); });
|
|
178
|
+
|
|
179
|
+
// Form field wrapping
|
|
180
|
+
if (label || help) {
|
|
181
|
+
const { wrapper } = createFormField(container, { label, error, help, required, success });
|
|
182
|
+
return wrapper;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return container;
|
|
186
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resizable — Split pane layout with draggable handle.
|
|
3
|
+
* Uses createDrag behavior for pointer-based resizing.
|
|
4
|
+
*
|
|
5
|
+
* @module decantr/components/resizable
|
|
6
|
+
*/
|
|
7
|
+
import { h } from '../core/index.js';
|
|
8
|
+
import { injectBase, cx } from './_base.js';
|
|
9
|
+
import { createDrag } from './_behaviors.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {Object} [props]
|
|
13
|
+
* @param {'horizontal'|'vertical'} [props.direction='horizontal']
|
|
14
|
+
* @param {number} [props.defaultSize=50] - Default size of first panel in %
|
|
15
|
+
* @param {number} [props.minSize=10] - Min size in %
|
|
16
|
+
* @param {number} [props.maxSize=90] - Max size in %
|
|
17
|
+
* @param {Function} [props.onResize] - Called with new size %
|
|
18
|
+
* @param {string} [props.class]
|
|
19
|
+
* @param {...Node} children - Exactly 2 children (panels)
|
|
20
|
+
* @returns {HTMLElement}
|
|
21
|
+
*/
|
|
22
|
+
export function Resizable(props = {}, ...children) {
|
|
23
|
+
injectBase();
|
|
24
|
+
const { direction = 'horizontal', defaultSize = 50, minSize = 10, maxSize = 90, onResize, class: cls, ...rest } = props;
|
|
25
|
+
|
|
26
|
+
const isVert = direction === 'vertical';
|
|
27
|
+
let size = defaultSize;
|
|
28
|
+
|
|
29
|
+
const panel1 = h('div', { class: 'd-resizable-panel' });
|
|
30
|
+
const panel2 = h('div', { class: 'd-resizable-panel' });
|
|
31
|
+
|
|
32
|
+
if (children[0]) panel1.appendChild(children[0]);
|
|
33
|
+
if (children[1]) panel2.appendChild(children[1]);
|
|
34
|
+
|
|
35
|
+
const handleBar = h('div', { class: 'd-resizable-handle-bar' });
|
|
36
|
+
const handle = h('div', {
|
|
37
|
+
class: cx('d-resizable-handle', isVert && 'd-resizable-handle-vertical'),
|
|
38
|
+
role: 'separator',
|
|
39
|
+
'aria-orientation': isVert ? 'horizontal' : 'vertical',
|
|
40
|
+
tabindex: '0',
|
|
41
|
+
'aria-valuenow': String(size),
|
|
42
|
+
'aria-valuemin': String(minSize),
|
|
43
|
+
'aria-valuemax': String(maxSize)
|
|
44
|
+
}, handleBar);
|
|
45
|
+
|
|
46
|
+
const container = h('div', {
|
|
47
|
+
class: cx('d-resizable', isVert && 'd-resizable-vertical', cls),
|
|
48
|
+
...rest
|
|
49
|
+
}, panel1, handle, panel2);
|
|
50
|
+
|
|
51
|
+
function applySize() {
|
|
52
|
+
const prop = isVert ? 'height' : 'width';
|
|
53
|
+
panel1.style[prop] = `${size}%`;
|
|
54
|
+
panel2.style[prop] = `${100 - size}%`;
|
|
55
|
+
handle.setAttribute('aria-valuenow', String(Math.round(size)));
|
|
56
|
+
if (onResize) onResize(size);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
createDrag(handle, {
|
|
60
|
+
onMove(x, y, dx, dy) {
|
|
61
|
+
const rect = container.getBoundingClientRect();
|
|
62
|
+
const total = isVert ? rect.height : rect.width;
|
|
63
|
+
const delta = isVert ? dy : dx;
|
|
64
|
+
const pct = (delta / total) * 100;
|
|
65
|
+
size = Math.max(minSize, Math.min(maxSize, defaultSize + pct));
|
|
66
|
+
applySize();
|
|
67
|
+
},
|
|
68
|
+
onStart() { container.style.userSelect = 'none'; },
|
|
69
|
+
onEnd() { container.style.userSelect = ''; }
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Keyboard support
|
|
73
|
+
handle.addEventListener('keydown', (e) => {
|
|
74
|
+
const step = e.shiftKey ? 10 : 2;
|
|
75
|
+
if (e.key === (isVert ? 'ArrowUp' : 'ArrowLeft')) { e.preventDefault(); size = Math.max(minSize, size - step); applySize(); }
|
|
76
|
+
else if (e.key === (isVert ? 'ArrowDown' : 'ArrowRight')) { e.preventDefault(); size = Math.min(maxSize, size + step); applySize(); }
|
|
77
|
+
else if (e.key === 'Home') { e.preventDefault(); size = minSize; applySize(); }
|
|
78
|
+
else if (e.key === 'End') { e.preventDefault(); size = maxSize; applySize(); }
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
applySize();
|
|
82
|
+
return container;
|
|
83
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result — Full-page result feedback (success, error, info, warning, 403, 404, 500).
|
|
3
|
+
*
|
|
4
|
+
* @module decantr/components/result
|
|
5
|
+
*/
|
|
6
|
+
import { h } from '../core/index.js';
|
|
7
|
+
import { injectBase, cx } from './_base.js';
|
|
8
|
+
import { icon as makeIcon } from './icon.js';
|
|
9
|
+
|
|
10
|
+
const STATUS_ICON_MAP = {
|
|
11
|
+
success: 'check-circle',
|
|
12
|
+
error: 'x-circle',
|
|
13
|
+
info: 'info',
|
|
14
|
+
warning: 'alert-triangle',
|
|
15
|
+
403: 'shield',
|
|
16
|
+
404: 'search',
|
|
17
|
+
500: 'alert-circle'
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {Object} [props]
|
|
22
|
+
* @param {'success'|'error'|'info'|'warning'|'403'|'404'|'500'} [props.status='info']
|
|
23
|
+
* @param {string} [props.title]
|
|
24
|
+
* @param {string} [props.subTitle]
|
|
25
|
+
* @param {Node} [props.icon] - Custom icon override
|
|
26
|
+
* @param {Node[]} [props.extra] - Action buttons at bottom
|
|
27
|
+
* @param {string} [props.class]
|
|
28
|
+
* @param {...Node} children - Additional content
|
|
29
|
+
* @returns {HTMLElement}
|
|
30
|
+
*/
|
|
31
|
+
export function Result(props = {}, ...children) {
|
|
32
|
+
injectBase();
|
|
33
|
+
const { status = 'info', title, subTitle, icon, extra, class: cls } = props;
|
|
34
|
+
|
|
35
|
+
const iconNode = icon
|
|
36
|
+
? (typeof icon === 'string' ? h('div', { class: 'd-result-icon' }, icon) : h('div', { class: 'd-result-icon' }, icon))
|
|
37
|
+
: h('div', { class: cx('d-result-icon', `d-result-icon-${status}`) }, makeIcon(STATUS_ICON_MAP[status] || 'info', { size: '3rem' }));
|
|
38
|
+
|
|
39
|
+
const el = h('div', { class: cx('d-result', cls) });
|
|
40
|
+
el.appendChild(iconNode);
|
|
41
|
+
if (title) el.appendChild(h('div', { class: 'd-result-title' }, title));
|
|
42
|
+
if (subTitle) el.appendChild(h('div', { class: 'd-result-subtitle' }, subTitle));
|
|
43
|
+
|
|
44
|
+
if (children.length) {
|
|
45
|
+
const content = h('div', { class: 'd-result-content' });
|
|
46
|
+
children.forEach(c => { if (c && c.nodeType) content.appendChild(c); });
|
|
47
|
+
el.appendChild(content);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (extra && extra.length) {
|
|
51
|
+
const actions = h('div', { class: 'd-result-extra' });
|
|
52
|
+
extra.forEach(node => { if (node && node.nodeType) actions.appendChild(node); });
|
|
53
|
+
el.appendChild(actions);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return el;
|
|
57
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScrollArea — Custom scrollable container with thin scrollbar styling.
|
|
3
|
+
*
|
|
4
|
+
* @module decantr/components/scroll-area
|
|
5
|
+
*/
|
|
6
|
+
import { h } from '../core/index.js';
|
|
7
|
+
import { injectBase, cx } from './_base.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Object} [props]
|
|
11
|
+
* @param {string} [props.height] - CSS height for the scrollable area
|
|
12
|
+
* @param {string} [props.width] - CSS width
|
|
13
|
+
* @param {'vertical'|'horizontal'|'both'} [props.direction='vertical']
|
|
14
|
+
* @param {string} [props.class]
|
|
15
|
+
* @param {...Node} children
|
|
16
|
+
* @returns {HTMLElement}
|
|
17
|
+
*/
|
|
18
|
+
export function ScrollArea(props = {}, ...children) {
|
|
19
|
+
injectBase();
|
|
20
|
+
const { height, width, direction = 'vertical', class: cls, ...rest } = props;
|
|
21
|
+
|
|
22
|
+
const style = {};
|
|
23
|
+
if (height) style.height = height;
|
|
24
|
+
if (width) style.width = width;
|
|
25
|
+
|
|
26
|
+
const viewportStyle = {};
|
|
27
|
+
if (direction === 'vertical') viewportStyle.overflowX = 'hidden';
|
|
28
|
+
else if (direction === 'horizontal') viewportStyle.overflowY = 'hidden';
|
|
29
|
+
|
|
30
|
+
const viewport = h('div', {
|
|
31
|
+
class: 'd-scrollarea-viewport',
|
|
32
|
+
style: Object.keys(viewportStyle).length ? viewportStyle : undefined,
|
|
33
|
+
tabindex: '0',
|
|
34
|
+
role: 'region',
|
|
35
|
+
'aria-label': 'Scrollable content'
|
|
36
|
+
}, ...children);
|
|
37
|
+
|
|
38
|
+
return h('div', {
|
|
39
|
+
class: cx('d-scrollarea', cls),
|
|
40
|
+
style: Object.keys(style).length ? style : undefined,
|
|
41
|
+
...rest
|
|
42
|
+
}, viewport);
|
|
43
|
+
}
|