tyrell-components 1.0.0-TC8 → 1.0.0-rc.21
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 +122 -0
- package/CHANGELOG.md +1531 -0
- package/README.md +71 -53
- package/css/tyrell-colors-static.css +1 -0
- package/css/tyrell-theme.css +1 -0
- package/css/tyrell.css +1 -1783
- package/dist/tyrell-colors-static.css +1 -0
- package/dist/tyrell-theme.css +1 -0
- package/dist/tyrell.css +1 -1783
- package/dist/tyrell.js +1 -1
- package/guides/AGENT_INSTRUCTIONS.md +124 -0
- package/guides/AI_GUIDE.md +53 -0
- package/guides/CSS_GUIDE.md +1016 -0
- package/guides/DATASTAR_TY_GUIDE.md +657 -0
- package/guides/ICONS_GUIDE.md +212 -0
- package/guides/TY_GUIDE.md +935 -0
- package/guides/clj/CLOJURESCRIPT_GUIDE.md +300 -0
- package/guides/clj/CODE_SPLITTING.md +279 -0
- package/guides/clj/COMPONENT_GUIDE.md +391 -0
- package/guides/clj/HELIX_TY_GUIDE.md +428 -0
- package/guides/clj/I18N_GUIDE.md +478 -0
- package/guides/clj/LAYOUT_GUIDE.md +273 -0
- package/guides/clj/QUICKSTART.md +266 -0
- package/guides/clj/REAGENT_TY_GUIDE.md +408 -0
- package/guides/clj/REPLICANT_TY_GUIDE.md +623 -0
- package/guides/clj/ROUTING_GUIDE.md +346 -0
- package/guides/clj/UIX_TY_GUIDE.md +319 -0
- package/guides/js/HTMX_TY_GUIDE.md +252 -0
- package/guides/js/JAVASCRIPT_GUIDE.md +388 -0
- package/guides/js/REACT_TY_GUIDE.md +983 -0
- package/guides/js/SVELTE_TY_GUIDE.md +682 -0
- package/guides/js/TYCOMPONENT_GUIDE.md +962 -0
- package/guides/js/VUE_TY_GUIDE.md +738 -0
- package/lib/base/ty-component.d.ts +57 -13
- package/lib/base/ty-component.js +266 -292
- package/lib/components/button.d.ts +42 -18
- package/lib/components/button.js +318 -235
- package/lib/components/calendar-month.d.ts +30 -47
- package/lib/components/calendar-month.js +455 -429
- package/lib/components/calendar-navigation.d.ts +41 -49
- package/lib/components/calendar-navigation.js +287 -346
- package/lib/components/calendar.d.ts +73 -83
- package/lib/components/calendar.js +837 -762
- package/lib/components/checkbox.d.ts +26 -75
- package/lib/components/checkbox.js +298 -391
- package/lib/components/copy.d.ts +20 -60
- package/lib/components/copy.js +276 -380
- package/lib/components/date-picker.d.ts +100 -183
- package/lib/components/date-picker.js +1155 -1570
- package/lib/components/file-upload.d.ts +122 -0
- package/lib/components/file-upload.js +451 -0
- package/lib/components/icon.d.ts +3 -24
- package/lib/components/icon.js +141 -230
- package/lib/components/input.d.ts +93 -108
- package/lib/components/input.js +734 -710
- package/lib/components/modal.d.ts +39 -29
- package/lib/components/modal.js +419 -438
- package/lib/components/option.d.ts +20 -35
- package/lib/components/option.js +184 -309
- package/lib/components/popup.d.ts +2 -17
- package/lib/components/popup.js +353 -347
- package/lib/components/radio.d.ts +33 -25
- package/lib/components/radio.js +433 -422
- package/lib/components/resize-observer.d.ts +3 -30
- package/lib/components/resize-observer.js +71 -103
- package/lib/components/scroll-container.d.ts +21 -14
- package/lib/components/scroll-container.js +292 -234
- package/lib/components/select.d.ts +446 -0
- package/lib/components/select.js +1381 -0
- package/lib/components/selected-tags.d.ts +60 -0
- package/lib/components/selected-tags.js +225 -0
- package/lib/components/sortable.d.ts +175 -0
- package/lib/components/sortable.js +1844 -0
- package/lib/components/step.d.ts +1 -6
- package/lib/components/step.js +62 -68
- package/lib/components/switch.d.ts +15 -15
- package/lib/components/switch.js +237 -231
- package/lib/components/tab.d.ts +50 -7
- package/lib/components/tab.js +203 -69
- package/lib/components/tabs.d.ts +19 -64
- package/lib/components/tabs.js +600 -618
- package/lib/components/tag.d.ts +17 -55
- package/lib/components/tag.js +235 -308
- package/lib/components/textarea.d.ts +58 -89
- package/lib/components/textarea.js +523 -573
- package/lib/components/tooltip.d.ts +8 -13
- package/lib/components/tooltip.js +322 -409
- package/lib/components/wizard.d.ts +7 -54
- package/lib/components/wizard.js +376 -606
- package/lib/icons/fontawesome/brands.d.ts +0 -1
- package/lib/icons/fontawesome/brands.js +0 -8
- package/lib/icons/fontawesome/regular.d.ts +0 -1
- package/lib/icons/fontawesome/regular.js +0 -8
- package/lib/icons/fontawesome/solid.d.ts +0 -1
- package/lib/icons/fontawesome/solid.js +0 -8
- package/lib/icons/heroicons/micro.d.ts +0 -1
- package/lib/icons/heroicons/micro.js +392 -400
- package/lib/icons/heroicons/mini.d.ts +0 -1
- package/lib/icons/heroicons/mini.js +382 -390
- package/lib/icons/heroicons/outline.d.ts +0 -1
- package/lib/icons/heroicons/outline.js +337 -345
- package/lib/icons/heroicons/solid.d.ts +0 -1
- package/lib/icons/heroicons/solid.js +407 -415
- package/lib/icons/lucide.d.ts +0 -1
- package/lib/icons/lucide.js +24479 -26351
- package/lib/icons/material/filled.d.ts +0 -1
- package/lib/icons/material/filled.js +9653 -9663
- package/lib/icons/material/outlined.d.ts +0 -1
- package/lib/icons/material/outlined.js +10271 -10281
- package/lib/icons/material/round.d.ts +0 -1
- package/lib/icons/material/round.js +10495 -10505
- package/lib/icons/material/sharp.d.ts +0 -1
- package/lib/icons/material/sharp.js +9905 -9915
- package/lib/icons/material/two-tone.d.ts +0 -1
- package/lib/icons/material/two-tone.js +12792 -12802
- package/lib/index.d.ts +15 -4
- package/lib/index.js +28 -38
- package/lib/styles/button.d.ts +24 -7
- package/lib/styles/button.js +298 -417
- package/lib/styles/calendar-month.d.ts +7 -6
- package/lib/styles/calendar-month.js +157 -179
- package/lib/styles/calendar-navigation.d.ts +2 -6
- package/lib/styles/calendar-navigation.js +108 -109
- package/lib/styles/calendar.d.ts +3 -3
- package/lib/styles/calendar.js +87 -23
- package/lib/styles/checkbox.d.ts +7 -6
- package/lib/styles/checkbox.js +101 -15
- package/lib/styles/copy.d.ts +3 -2
- package/lib/styles/copy.js +91 -71
- package/lib/styles/custom-scrollbar.d.ts +1 -2
- package/lib/styles/custom-scrollbar.js +80 -115
- package/lib/styles/date-picker.d.ts +4 -6
- package/lib/styles/date-picker.js +320 -352
- package/lib/styles/field-size.d.ts +6 -0
- package/lib/styles/field-size.js +91 -0
- package/lib/styles/file-upload.d.ts +1 -0
- package/lib/styles/file-upload.js +196 -0
- package/lib/styles/icon.d.ts +2 -6
- package/lib/styles/icon.js +92 -170
- package/lib/styles/input.d.ts +4 -7
- package/lib/styles/input.js +148 -643
- package/lib/styles/modal.d.ts +1 -2
- package/lib/styles/modal.js +127 -108
- package/lib/styles/option.d.ts +2 -6
- package/lib/styles/option.js +53 -96
- package/lib/styles/popup.d.ts +1 -2
- package/lib/styles/popup.js +47 -77
- package/lib/styles/radio.d.ts +3 -2
- package/lib/styles/radio.js +90 -116
- package/lib/styles/resize-observer.d.ts +1 -2
- package/lib/styles/resize-observer.js +2 -12
- package/lib/styles/scroll-container.d.ts +1 -2
- package/lib/styles/scroll-container.js +103 -146
- package/lib/styles/select-base.d.ts +8 -0
- package/lib/styles/select-base.js +747 -0
- package/lib/styles/select.d.ts +11 -0
- package/lib/styles/select.js +229 -0
- package/lib/styles/sortable.d.ts +16 -0
- package/lib/styles/sortable.js +85 -0
- package/lib/styles/step.d.ts +1 -2
- package/lib/styles/step.js +15 -34
- package/lib/styles/switch.d.ts +3 -2
- package/lib/styles/switch.js +52 -68
- package/lib/styles/tab.d.ts +1 -2
- package/lib/styles/tab.js +86 -34
- package/lib/styles/tabs.d.ts +3 -11
- package/lib/styles/tabs.js +204 -162
- package/lib/styles/tag.d.ts +2 -6
- package/lib/styles/tag.js +170 -359
- package/lib/styles/textarea.d.ts +1 -2
- package/lib/styles/textarea.js +238 -306
- package/lib/styles/tooltip.d.ts +4 -3
- package/lib/styles/tooltip.js +3 -131
- package/lib/styles/wizard.d.ts +8 -20
- package/lib/styles/wizard.js +306 -295
- package/lib/types/common.d.ts +9 -8
- package/lib/types/common.js +8 -5
- package/lib/utils/calendar-utils.d.ts +49 -65
- package/lib/utils/calendar-utils.js +158 -343
- package/lib/utils/custom-scrollbar.d.ts +6 -20
- package/lib/utils/custom-scrollbar.js +273 -317
- package/lib/utils/flavor-sheet.d.ts +31 -0
- package/lib/utils/flavor-sheet.js +17 -0
- package/lib/utils/icon-registry.d.ts +0 -15
- package/lib/utils/icon-registry.js +138 -279
- package/lib/utils/icons.d.ts +9 -0
- package/lib/utils/icons.js +1 -0
- package/lib/utils/loader-registry.d.ts +34 -0
- package/lib/utils/loader-registry.js +11 -0
- package/lib/utils/locale.d.ts +2 -80
- package/lib/utils/locale.js +30 -205
- package/lib/utils/mobile.d.ts +0 -1
- package/lib/utils/mobile.js +1 -18
- package/lib/utils/number-format.d.ts +6 -24
- package/lib/utils/number-format.js +53 -136
- package/lib/utils/positioning.d.ts +72 -22
- package/lib/utils/positioning.js +224 -298
- package/lib/utils/property-capture.d.ts +5 -27
- package/lib/utils/property-capture.js +36 -144
- package/lib/utils/property-manager.d.ts +6 -6
- package/lib/utils/property-manager.js +127 -196
- package/lib/utils/resize-observer.d.ts +0 -1
- package/lib/utils/resize-observer.js +23 -59
- package/lib/utils/scroll-lock.d.ts +10 -11
- package/lib/utils/scroll-lock.js +165 -173
- package/lib/utils/styles.d.ts +0 -6
- package/lib/utils/styles.js +17 -48
- package/lib/utils/upgrade-properties.d.ts +21 -0
- package/lib/utils/upgrade-properties.js +47 -0
- package/lib/utils/validity.d.ts +122 -0
- package/lib/utils/validity.js +289 -0
- package/lib/version.d.ts +1 -2
- package/lib/version.js +1 -11
- package/package.json +66 -18
- package/lib/base/ty-component.d.ts.map +0 -1
- package/lib/base/ty-component.js.map +0 -1
- package/lib/components/button.d.ts.map +0 -1
- package/lib/components/button.js.map +0 -1
- package/lib/components/calendar-month.d.ts.map +0 -1
- package/lib/components/calendar-month.js.map +0 -1
- package/lib/components/calendar-navigation.d.ts.map +0 -1
- package/lib/components/calendar-navigation.js.map +0 -1
- package/lib/components/calendar.d.ts.map +0 -1
- package/lib/components/calendar.js.map +0 -1
- package/lib/components/checkbox.d.ts.map +0 -1
- package/lib/components/checkbox.js.map +0 -1
- package/lib/components/copy.d.ts.map +0 -1
- package/lib/components/copy.js.map +0 -1
- package/lib/components/date-picker.d.ts.map +0 -1
- package/lib/components/date-picker.js.map +0 -1
- package/lib/components/dropdown.d.ts +0 -402
- package/lib/components/dropdown.d.ts.map +0 -1
- package/lib/components/dropdown.js +0 -1564
- package/lib/components/dropdown.js.map +0 -1
- package/lib/components/icon.d.ts.map +0 -1
- package/lib/components/icon.js.map +0 -1
- package/lib/components/input.d.ts.map +0 -1
- package/lib/components/input.js.map +0 -1
- package/lib/components/modal.d.ts.map +0 -1
- package/lib/components/modal.js.map +0 -1
- package/lib/components/multiselect.d.ts +0 -397
- package/lib/components/multiselect.d.ts.map +0 -1
- package/lib/components/multiselect.js +0 -1580
- package/lib/components/multiselect.js.map +0 -1
- package/lib/components/option.d.ts.map +0 -1
- package/lib/components/option.js.map +0 -1
- package/lib/components/popup.d.ts.map +0 -1
- package/lib/components/popup.js.map +0 -1
- package/lib/components/radio.d.ts.map +0 -1
- package/lib/components/radio.js.map +0 -1
- package/lib/components/resize-observer.d.ts.map +0 -1
- package/lib/components/resize-observer.js.map +0 -1
- package/lib/components/scroll-container.d.ts.map +0 -1
- package/lib/components/scroll-container.js.map +0 -1
- package/lib/components/step.d.ts.map +0 -1
- package/lib/components/step.js.map +0 -1
- package/lib/components/switch.d.ts.map +0 -1
- package/lib/components/switch.js.map +0 -1
- package/lib/components/tab.d.ts.map +0 -1
- package/lib/components/tab.js.map +0 -1
- package/lib/components/tabs.d.ts.map +0 -1
- package/lib/components/tabs.js.map +0 -1
- package/lib/components/tag.d.ts.map +0 -1
- package/lib/components/tag.js.map +0 -1
- package/lib/components/textarea.d.ts.map +0 -1
- package/lib/components/textarea.js.map +0 -1
- package/lib/components/tooltip.d.ts.map +0 -1
- package/lib/components/tooltip.js.map +0 -1
- package/lib/components/wizard.d.ts.map +0 -1
- package/lib/components/wizard.js.map +0 -1
- package/lib/icons/fontawesome/brands.d.ts.map +0 -1
- package/lib/icons/fontawesome/brands.js.map +0 -1
- package/lib/icons/fontawesome/regular.d.ts.map +0 -1
- package/lib/icons/fontawesome/regular.js.map +0 -1
- package/lib/icons/fontawesome/solid.d.ts.map +0 -1
- package/lib/icons/fontawesome/solid.js.map +0 -1
- package/lib/icons/heroicons/micro.d.ts.map +0 -1
- package/lib/icons/heroicons/micro.js.map +0 -1
- package/lib/icons/heroicons/mini.d.ts.map +0 -1
- package/lib/icons/heroicons/mini.js.map +0 -1
- package/lib/icons/heroicons/outline.d.ts.map +0 -1
- package/lib/icons/heroicons/outline.js.map +0 -1
- package/lib/icons/heroicons/solid.d.ts.map +0 -1
- package/lib/icons/heroicons/solid.js.map +0 -1
- package/lib/icons/lucide.d.ts.map +0 -1
- package/lib/icons/lucide.js.map +0 -1
- package/lib/icons/material/filled.d.ts.map +0 -1
- package/lib/icons/material/filled.js.map +0 -1
- package/lib/icons/material/outlined.d.ts.map +0 -1
- package/lib/icons/material/outlined.js.map +0 -1
- package/lib/icons/material/round.d.ts.map +0 -1
- package/lib/icons/material/round.js.map +0 -1
- package/lib/icons/material/sharp.d.ts.map +0 -1
- package/lib/icons/material/sharp.js.map +0 -1
- package/lib/icons/material/two-tone.d.ts.map +0 -1
- package/lib/icons/material/two-tone.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/styles/button.d.ts.map +0 -1
- package/lib/styles/button.js.map +0 -1
- package/lib/styles/calendar-month.d.ts.map +0 -1
- package/lib/styles/calendar-month.js.map +0 -1
- package/lib/styles/calendar-navigation.d.ts.map +0 -1
- package/lib/styles/calendar-navigation.js.map +0 -1
- package/lib/styles/calendar.d.ts.map +0 -1
- package/lib/styles/calendar.js.map +0 -1
- package/lib/styles/checkbox.d.ts.map +0 -1
- package/lib/styles/checkbox.js.map +0 -1
- package/lib/styles/copy.d.ts.map +0 -1
- package/lib/styles/copy.js.map +0 -1
- package/lib/styles/custom-scrollbar.d.ts.map +0 -1
- package/lib/styles/custom-scrollbar.js.map +0 -1
- package/lib/styles/date-picker.d.ts.map +0 -1
- package/lib/styles/date-picker.js.map +0 -1
- package/lib/styles/dropdown.d.ts +0 -12
- package/lib/styles/dropdown.d.ts.map +0 -1
- package/lib/styles/dropdown.js +0 -983
- package/lib/styles/dropdown.js.map +0 -1
- package/lib/styles/icon.d.ts.map +0 -1
- package/lib/styles/icon.js.map +0 -1
- package/lib/styles/input.d.ts.map +0 -1
- package/lib/styles/input.js.map +0 -1
- package/lib/styles/modal.d.ts.map +0 -1
- package/lib/styles/modal.js.map +0 -1
- package/lib/styles/multiselect.d.ts +0 -6
- package/lib/styles/multiselect.d.ts.map +0 -1
- package/lib/styles/multiselect.js +0 -774
- package/lib/styles/multiselect.js.map +0 -1
- package/lib/styles/option.d.ts.map +0 -1
- package/lib/styles/option.js.map +0 -1
- package/lib/styles/popup.d.ts.map +0 -1
- package/lib/styles/popup.js.map +0 -1
- package/lib/styles/radio.d.ts.map +0 -1
- package/lib/styles/radio.js.map +0 -1
- package/lib/styles/resize-observer.d.ts.map +0 -1
- package/lib/styles/resize-observer.js.map +0 -1
- package/lib/styles/scroll-container.d.ts.map +0 -1
- package/lib/styles/scroll-container.js.map +0 -1
- package/lib/styles/step.d.ts.map +0 -1
- package/lib/styles/step.js.map +0 -1
- package/lib/styles/switch.d.ts.map +0 -1
- package/lib/styles/switch.js.map +0 -1
- package/lib/styles/tab.d.ts.map +0 -1
- package/lib/styles/tab.js.map +0 -1
- package/lib/styles/tabs.d.ts.map +0 -1
- package/lib/styles/tabs.js.map +0 -1
- package/lib/styles/tag.d.ts.map +0 -1
- package/lib/styles/tag.js.map +0 -1
- package/lib/styles/textarea.d.ts.map +0 -1
- package/lib/styles/textarea.js.map +0 -1
- package/lib/styles/tooltip.d.ts.map +0 -1
- package/lib/styles/tooltip.js.map +0 -1
- package/lib/styles/wizard.d.ts.map +0 -1
- package/lib/styles/wizard.js.map +0 -1
- package/lib/types/common.d.ts.map +0 -1
- package/lib/types/common.js.map +0 -1
- package/lib/utils/calendar-utils.d.ts.map +0 -1
- package/lib/utils/calendar-utils.js.map +0 -1
- package/lib/utils/custom-scrollbar.d.ts.map +0 -1
- package/lib/utils/custom-scrollbar.js.map +0 -1
- package/lib/utils/icon-registry.d.ts.map +0 -1
- package/lib/utils/icon-registry.js.map +0 -1
- package/lib/utils/locale.d.ts.map +0 -1
- package/lib/utils/locale.js.map +0 -1
- package/lib/utils/mobile.d.ts.map +0 -1
- package/lib/utils/mobile.js.map +0 -1
- package/lib/utils/number-format.d.ts.map +0 -1
- package/lib/utils/number-format.js.map +0 -1
- package/lib/utils/parse-boolean.d.ts +0 -39
- package/lib/utils/parse-boolean.d.ts.map +0 -1
- package/lib/utils/parse-boolean.js +0 -58
- package/lib/utils/parse-boolean.js.map +0 -1
- package/lib/utils/positioning.d.ts.map +0 -1
- package/lib/utils/positioning.js.map +0 -1
- package/lib/utils/property-capture.d.ts.map +0 -1
- package/lib/utils/property-capture.js.map +0 -1
- package/lib/utils/property-manager.d.ts.map +0 -1
- package/lib/utils/property-manager.js.map +0 -1
- package/lib/utils/resize-observer.d.ts.map +0 -1
- package/lib/utils/resize-observer.js.map +0 -1
- package/lib/utils/scroll-lock.d.ts.map +0 -1
- package/lib/utils/scroll-lock.js.map +0 -1
- package/lib/utils/styles.d.ts.map +0 -1
- package/lib/utils/styles.js.map +0 -1
- package/lib/version.d.ts.map +0 -1
- package/lib/version.js.map +0 -1
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
# Building Web Components with tyrell.shim
|
|
2
|
+
|
|
3
|
+
Turn any ClojureScript render function into a standards-compliant Web Component.
|
|
4
|
+
|
|
5
|
+
## Basic Pattern
|
|
6
|
+
|
|
7
|
+
```clojure
|
|
8
|
+
(ns app.components
|
|
9
|
+
(:require [tyrell.shim :as shim]))
|
|
10
|
+
|
|
11
|
+
(defn render! [^js el]
|
|
12
|
+
(let [root (shim/ensure-shadow el)]
|
|
13
|
+
(set! (.-innerHTML root) "<p>Hello!</p>")))
|
|
14
|
+
|
|
15
|
+
(shim/define! "my-component"
|
|
16
|
+
{:observed [:name :count] ;; Attributes to watch
|
|
17
|
+
:connected render! ;; Called when added to DOM
|
|
18
|
+
:disconnected cleanup! ;; Called when removed
|
|
19
|
+
:attr (fn [el delta] (render! el)) ;; Batched attribute changes
|
|
20
|
+
:prop (fn [el delta] (render! el)) ;; Batched property changes
|
|
21
|
+
:form-associated true}) ;; Enable form participation
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Configuration Options
|
|
27
|
+
|
|
28
|
+
| Key | Type | Description |
|
|
29
|
+
|-----|------|-------------|
|
|
30
|
+
| `:observed` | `[keyword]` | Attribute names to watch for changes |
|
|
31
|
+
| `:props` | `{keyword any}` | Property accessors (keys define available props) |
|
|
32
|
+
| `:connected` | `(fn [el])` | Lifecycle: element added to DOM |
|
|
33
|
+
| `:disconnected` | `(fn [el])` | Lifecycle: element removed from DOM |
|
|
34
|
+
| `:adopted` | `(fn [el old-doc new-doc])` | Lifecycle: element moved to new document |
|
|
35
|
+
| `:attr` | `(fn [el delta])` | Batched attribute changes (delta is a map) |
|
|
36
|
+
| `:prop` | `(fn [el delta])` | Batched property changes (delta is a map) |
|
|
37
|
+
| `:form-associated` | `boolean` | Enable form participation |
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Attribute Helpers
|
|
42
|
+
|
|
43
|
+
```clojure
|
|
44
|
+
;; Read attributes
|
|
45
|
+
(shim/attr el "name") ;; Raw string
|
|
46
|
+
(shim/parse-int-attr el "count") ;; Parse as integer
|
|
47
|
+
(shim/parse-float-attr el "ratio") ;; Parse as float
|
|
48
|
+
(shim/parse-bool-attr el "disabled") ;; Presence = true, "false" = false
|
|
49
|
+
(shim/parse-json-attr el "config") ;; Parse JSON to map
|
|
50
|
+
(shim/parse-edn-attr el "data") ;; Parse EDN
|
|
51
|
+
|
|
52
|
+
;; Write attributes
|
|
53
|
+
(shim/set-attr! el "name" "value")
|
|
54
|
+
(shim/rm-attr! el "disabled")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## With Replicant
|
|
60
|
+
|
|
61
|
+
```clojure
|
|
62
|
+
(ns app.components
|
|
63
|
+
(:require [replicant.dom :as d]
|
|
64
|
+
[tyrell.shim :as shim]))
|
|
65
|
+
|
|
66
|
+
(defn counter-view [count on-click]
|
|
67
|
+
[:div.ty-elevated.p-6.rounded-lg.space-y-4
|
|
68
|
+
[:div.ty-text++.text-4xl.text-center count]
|
|
69
|
+
[:div.flex.gap-2.justify-center
|
|
70
|
+
[:ty-button {:flavor "neutral" :on {:click #(on-click dec)}} "-"]
|
|
71
|
+
[:ty-button {:flavor "primary" :on {:click #(on-click inc)}} "+"]]])
|
|
72
|
+
|
|
73
|
+
(defn render! [^js el]
|
|
74
|
+
(let [root (shim/ensure-shadow el)
|
|
75
|
+
get-count #(or (.-_count el) 0)
|
|
76
|
+
set-count! (fn [f]
|
|
77
|
+
(set! (.-_count el) (f (get-count)))
|
|
78
|
+
(render! el))]
|
|
79
|
+
(d/render root (counter-view (get-count) set-count!))))
|
|
80
|
+
|
|
81
|
+
(shim/define! "replicant-counter"
|
|
82
|
+
{:observed [:initial]
|
|
83
|
+
:connected (fn [el]
|
|
84
|
+
(set! (.-_count el) (or (shim/parse-int-attr el "initial") 0))
|
|
85
|
+
(render! el))
|
|
86
|
+
:attr (fn [el {:strs [initial]}]
|
|
87
|
+
(when initial
|
|
88
|
+
(set! (.-_count el) (js/parseInt initial))
|
|
89
|
+
(render! el)))})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
```html
|
|
93
|
+
<replicant-counter initial="10"></replicant-counter>
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## With UIx
|
|
99
|
+
|
|
100
|
+
```clojure
|
|
101
|
+
(ns app.components
|
|
102
|
+
(:require [uix.core :as uix :refer [defui $]]
|
|
103
|
+
[uix.dom]
|
|
104
|
+
[tyrell.shim :as shim]))
|
|
105
|
+
|
|
106
|
+
(defui counter [{:keys [initial]}]
|
|
107
|
+
(let [[count set-count] (uix/use-state (or initial 0))]
|
|
108
|
+
($ :div.ty-elevated.p-6.rounded-lg.space-y-4
|
|
109
|
+
($ :div.ty-text++.text-4xl.text-center count)
|
|
110
|
+
($ :div.flex.gap-2.justify-center
|
|
111
|
+
($ :ty-button {:flavor "neutral" :on-click #(set-count dec)} "-")
|
|
112
|
+
($ :ty-button {:flavor "primary" :on-click #(set-count inc)} "+")))))
|
|
113
|
+
|
|
114
|
+
(defn render! [^js el]
|
|
115
|
+
(let [root (shim/ensure-shadow el)
|
|
116
|
+
initial (shim/parse-int-attr el "initial")]
|
|
117
|
+
;; UIx needs a root - create once, reuse
|
|
118
|
+
(when-not (.-_uixRoot el)
|
|
119
|
+
(set! (.-_uixRoot el) (uix.dom/create-root root)))
|
|
120
|
+
(uix.dom/render-root (.-_uixRoot el)
|
|
121
|
+
($ counter {:initial initial}))))
|
|
122
|
+
|
|
123
|
+
(shim/define! "uix-counter"
|
|
124
|
+
{:observed [:initial]
|
|
125
|
+
:connected render!
|
|
126
|
+
:disconnected (fn [el]
|
|
127
|
+
(when-let [root (.-_uixRoot el)]
|
|
128
|
+
(uix.dom/unmount-root root)))})
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## With Reagent
|
|
134
|
+
|
|
135
|
+
```clojure
|
|
136
|
+
(ns app.components
|
|
137
|
+
(:require [reagent.core :as r]
|
|
138
|
+
[reagent.dom :as rdom]
|
|
139
|
+
[tyrell.shim :as shim]))
|
|
140
|
+
|
|
141
|
+
(defn counter [initial-count]
|
|
142
|
+
(let [count (r/atom (or initial-count 0))]
|
|
143
|
+
(fn []
|
|
144
|
+
[:div.ty-elevated.p-6.rounded-lg.space-y-4
|
|
145
|
+
[:div.ty-text++.text-4xl.text-center @count]
|
|
146
|
+
[:div.flex.gap-2.justify-center
|
|
147
|
+
[:ty-button {:flavor "neutral" :on-click #(swap! count dec)} "-"]
|
|
148
|
+
[:ty-button {:flavor "primary" :on-click #(swap! count inc)} "+"]]])))
|
|
149
|
+
|
|
150
|
+
(defn render! [^js el]
|
|
151
|
+
(let [root (shim/ensure-shadow el)
|
|
152
|
+
initial (shim/parse-int-attr el "initial")]
|
|
153
|
+
(rdom/render [counter initial] root)))
|
|
154
|
+
|
|
155
|
+
(shim/define! "reagent-counter"
|
|
156
|
+
{:observed [:initial]
|
|
157
|
+
:connected render!
|
|
158
|
+
:disconnected (fn [el]
|
|
159
|
+
(rdom/unmount-component-at-node (.-shadowRoot el)))})
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
---
|
|
163
|
+
|
|
164
|
+
## Shadow DOM & Styling
|
|
165
|
+
|
|
166
|
+
### Inline Styles
|
|
167
|
+
|
|
168
|
+
```clojure
|
|
169
|
+
(ns app.components
|
|
170
|
+
(:require [tyrell.shim :as shim]
|
|
171
|
+
[tyrell.css :refer [ensure-styles!]]))
|
|
172
|
+
|
|
173
|
+
(def my-styles
|
|
174
|
+
".container { padding: 1rem; }
|
|
175
|
+
.title { font-size: 1.5rem; }")
|
|
176
|
+
|
|
177
|
+
(defn render! [^js el]
|
|
178
|
+
(let [root (shim/ensure-shadow el)]
|
|
179
|
+
;; Inject styles into shadow DOM (deduped by ID)
|
|
180
|
+
(ensure-styles! root my-styles "my-component")
|
|
181
|
+
|
|
182
|
+
;; Tyrell design system classes work inside shadow DOM
|
|
183
|
+
(set! (.-innerHTML root)
|
|
184
|
+
"<div class='ty-elevated p-4 rounded-lg'>
|
|
185
|
+
<h2 class='ty-text+ mb-2'>Title</h2>
|
|
186
|
+
<p class='ty-text-'>Content here</p>
|
|
187
|
+
</div>")))
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### defstyles Macro (Compile-time CSS)
|
|
191
|
+
|
|
192
|
+
Load CSS files at compile time for better organization:
|
|
193
|
+
|
|
194
|
+
```clojure
|
|
195
|
+
(ns app.components.card
|
|
196
|
+
(:require [tyrell.shim :as shim]
|
|
197
|
+
[tyrell.css :refer [ensure-styles!]])
|
|
198
|
+
(:require-macros [tyrell.css :refer [defstyles]]))
|
|
199
|
+
|
|
200
|
+
;; Loads app/components/card.css at compile time
|
|
201
|
+
;; Creates a CSSStyleSheet for efficient shadow DOM adoption
|
|
202
|
+
(defstyles card-styles)
|
|
203
|
+
|
|
204
|
+
;; Or specify a custom path
|
|
205
|
+
(defstyles card-styles "custom/path/card.css")
|
|
206
|
+
|
|
207
|
+
(defn render! [^js el]
|
|
208
|
+
(let [root (shim/ensure-shadow el)]
|
|
209
|
+
(ensure-styles! root card-styles "app-card")
|
|
210
|
+
;; render...
|
|
211
|
+
))
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Create the CSS file alongside your ClojureScript:
|
|
215
|
+
|
|
216
|
+
```css
|
|
217
|
+
/* app/components/card.css */
|
|
218
|
+
:host {
|
|
219
|
+
display: block;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.card {
|
|
223
|
+
padding: var(--ty-spacing-4);
|
|
224
|
+
border-radius: var(--ty-radius-lg);
|
|
225
|
+
background: var(--ty-surface-elevated);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.card-title {
|
|
229
|
+
font-size: var(--ty-text-lg);
|
|
230
|
+
color: var(--ty-text-strong);
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Benefits:
|
|
235
|
+
- CSS is bundled at compile time (no runtime fetch)
|
|
236
|
+
- Uses `CSSStyleSheet` for efficient style sharing
|
|
237
|
+
- CSS variables from Tyrell design system are available
|
|
238
|
+
- Better editor support with separate `.css` files
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Form Participation
|
|
243
|
+
|
|
244
|
+
```clojure
|
|
245
|
+
(shim/define! "my-input"
|
|
246
|
+
{:observed [:value :name]
|
|
247
|
+
:form-associated true
|
|
248
|
+
:connected (fn [el]
|
|
249
|
+
;; Access ElementInternals
|
|
250
|
+
(let [internals (.-_internals el)]
|
|
251
|
+
;; Set form value
|
|
252
|
+
(.setFormValue internals "initial-value")
|
|
253
|
+
;; Access associated form
|
|
254
|
+
(.-form internals)))})
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Properties vs Attributes
|
|
260
|
+
|
|
261
|
+
**Attributes** are strings in HTML. **Properties** are JS values on the element.
|
|
262
|
+
|
|
263
|
+
```clojure
|
|
264
|
+
;; Define properties
|
|
265
|
+
(shim/define! "my-component"
|
|
266
|
+
{:props {:config nil ;; Will create .config property
|
|
267
|
+
:on-change nil} ;; Will create .onChange property
|
|
268
|
+
:prop (fn [el delta]
|
|
269
|
+
;; delta = {"config" new-value, "onChange" new-fn}
|
|
270
|
+
(render! el))})
|
|
271
|
+
|
|
272
|
+
;; Set properties programmatically
|
|
273
|
+
(shim/set-props! el {:config {:foo "bar"}
|
|
274
|
+
:on-change #(js/console.log %)})
|
|
275
|
+
|
|
276
|
+
;; Read properties
|
|
277
|
+
(shim/get-props el) ;; => {:config {:foo "bar"} ...}
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
---
|
|
281
|
+
|
|
282
|
+
## Hot Reload
|
|
283
|
+
|
|
284
|
+
The shim supports shadow-cljs hot reload automatically:
|
|
285
|
+
|
|
286
|
+
```clojure
|
|
287
|
+
(ns app.components
|
|
288
|
+
(:require [tyrell.shim :as shim]))
|
|
289
|
+
|
|
290
|
+
;; Re-defining a component in dev mode refreshes all instances
|
|
291
|
+
(shim/define! "my-component" {...})
|
|
292
|
+
|
|
293
|
+
;; Optional: Add hooks for cleanup/setup
|
|
294
|
+
(defn ^:dev/before-load stop []
|
|
295
|
+
(js/console.log "Preparing for reload..."))
|
|
296
|
+
|
|
297
|
+
(defn ^:dev/after-load start []
|
|
298
|
+
(js/console.log "Reloaded!"))
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Initial Attributes (React-compatible)
|
|
304
|
+
|
|
305
|
+
For one-time initialization attributes that shouldn't override user state:
|
|
306
|
+
|
|
307
|
+
```clojure
|
|
308
|
+
(defn render! [^js el]
|
|
309
|
+
;; Only read these on first render
|
|
310
|
+
(let [initial (shim/get-initial-attrs el
|
|
311
|
+
{:view-year js/parseInt
|
|
312
|
+
:view-month js/parseInt
|
|
313
|
+
:min-date parse-date})]
|
|
314
|
+
(when (seq initial)
|
|
315
|
+
(apply-initial-state! el initial))
|
|
316
|
+
|
|
317
|
+
(render-view! el)))
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## Complete Example: Date Input
|
|
323
|
+
|
|
324
|
+
```clojure
|
|
325
|
+
(ns app.date-input
|
|
326
|
+
(:require [replicant.dom :as d]
|
|
327
|
+
[tyrell.shim :as shim]
|
|
328
|
+
[tyrell.css :refer [ensure-styles!]]))
|
|
329
|
+
|
|
330
|
+
(def styles
|
|
331
|
+
".wrapper { position: relative; }
|
|
332
|
+
.popup { position: absolute; top: 100%; left: 0; }")
|
|
333
|
+
|
|
334
|
+
(defn date-input-view [{:keys [value label on-change on-toggle open?]}]
|
|
335
|
+
[:div.wrapper
|
|
336
|
+
[:ty-input
|
|
337
|
+
{:label label
|
|
338
|
+
:value value
|
|
339
|
+
:readonly true
|
|
340
|
+
:on {:click on-toggle}}]
|
|
341
|
+
(when open?
|
|
342
|
+
[:div.popup.ty-floating.p-2.rounded-lg.shadow-lg
|
|
343
|
+
[:ty-calendar
|
|
344
|
+
{:value value
|
|
345
|
+
:on {:change #(on-change (.. % -detail -value))}}]])])
|
|
346
|
+
|
|
347
|
+
(defn render! [^js el]
|
|
348
|
+
(let [root (shim/ensure-shadow el)]
|
|
349
|
+
(ensure-styles! root styles "date-input")
|
|
350
|
+
(d/render root
|
|
351
|
+
(date-input-view
|
|
352
|
+
{:value (.-_value el)
|
|
353
|
+
:label (or (shim/attr el "label") "Date")
|
|
354
|
+
:open? (.-_open el)
|
|
355
|
+
:on-toggle #(do (set! (.-_open el) (not (.-_open el)))
|
|
356
|
+
(render! el))
|
|
357
|
+
:on-change #(do (set! (.-_value el) %)
|
|
358
|
+
(set! (.-_open el) false)
|
|
359
|
+
(.dispatchEvent el (js/CustomEvent. "change"
|
|
360
|
+
#js {:detail #js {:value %}}))
|
|
361
|
+
(render! el))}))))
|
|
362
|
+
|
|
363
|
+
(shim/define! "app-date-input"
|
|
364
|
+
{:observed [:value :label]
|
|
365
|
+
:props {:value nil}
|
|
366
|
+
:connected (fn [el]
|
|
367
|
+
(set! (.-_value el) (shim/attr el "value"))
|
|
368
|
+
(set! (.-_open el) false)
|
|
369
|
+
(render! el))
|
|
370
|
+
:attr (fn [el delta]
|
|
371
|
+
(when-let [v (get delta "value")]
|
|
372
|
+
(set! (.-_value el) v))
|
|
373
|
+
(render! el))
|
|
374
|
+
:prop (fn [el delta]
|
|
375
|
+
(when-let [v (get delta "value")]
|
|
376
|
+
(set! (.-_value el) v))
|
|
377
|
+
(render! el))})
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
```html
|
|
381
|
+
<app-date-input label="Start Date" value="2025-01-15"></app-date-input>
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
386
|
+
## See Also
|
|
387
|
+
|
|
388
|
+
- [Code Splitting Guide](CODE_SPLITTING.md) - Lazy loading and bundle optimization (in guides/)
|
|
389
|
+
- [Tyrell Components Source](components/ty/components/) - Reference implementations
|
|
390
|
+
- [tyrell.shim Source](src/ty/shim.cljs) - Full API
|
|
391
|
+
- [tyrell.css](src/ty/css.cljs) - Style injection utilities
|