kiso 0.4.0.pre → 0.4.2.pre
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -1
- data/app/assets/tailwind/kiso/engine.css +38 -27
- data/app/assets/tailwind/kiso/palettes/blue.css +1 -1
- data/app/assets/tailwind/kiso/palettes/green.css +1 -1
- data/app/assets/tailwind/kiso/palettes/orange.css +1 -1
- data/app/assets/tailwind/kiso/palettes/violet.css +1 -1
- data/app/assets/tailwind/kiso/palettes/zinc.css +1 -1
- data/app/helpers/kiso/app_component_helper.rb +21 -2
- data/app/helpers/kiso/component_helper.rb +49 -3
- data/app/helpers/kiso/ui_context_helper.rb +56 -7
- data/app/views/kiso/components/_app.html.erb +2 -2
- data/lib/generators/kiso/component/templates/partial.html.erb.tt +2 -4
- data/lib/generators/kiso/component/templates/sub_part_partial.html.erb.tt +2 -4
- data/lib/kiso/engine.rb +4 -0
- data/lib/kiso/themes/layout.rb +11 -2
- data/lib/kiso/version.rb +1 -1
- data/lib/tasks/kiso.rake +36 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4e7e4247e68272499ab572c3aa2ed94ad54860cf075f0b4e3240a1b11fd909d6
|
|
4
|
+
data.tar.gz: 87e9710cb6428055adad01d89a4357e735ac5c8b326c547b01d696d208501cf8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9f0842c23bdf92f06c826614ac8eb81d427eb136ea5fa2d6f735886387790cccda7943d450e8e771a7405cb9d6017eb2c1a5b00386b499b2c079ff933b520ec2
|
|
7
|
+
data.tar.gz: 1322bed3abb54da45bb4163e7fa5ca5919efbb6af07f505606dc17e65ac100f5fbc6d438e336347bdb44a09f70a2a7f3c413df876ace869adcd2b7a758ee725a
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.2.pre] - 2026-03-08
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `scope:` prop for sharing domain locals from parent components to sub-parts — `appui(:room_card, scope: { room: room })` makes `room:` available to all sub-parts automatically without repeating it on every call. Explicit kwargs on sub-part calls override scope values. One level deep only (parent to its own sub-parts).
|
|
15
|
+
|
|
16
|
+
## [0.4.1.pre] - 2026-03-08
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- `center:` variant on App layout component — `kui(:app, center: true)` applies full-viewport centering for login pages and similar single-focus layouts
|
|
21
|
+
- `kui_tag` / `appui_tag` helpers — collapse the common `content_tag` + `kiso_prepare_options` + theme rendering boilerplate into a single call; component generator templates now use `appui_tag` by default
|
|
22
|
+
- Shade scale auto-wiring — host apps defining `--color-primary-50` through `--color-primary-950` in their Tailwind `@theme` block now automatically feed into Kiso's semantic color tokens (shade 500 for light mode, 400 for dark mode, matching Nuxt UI conventions)
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- Palette CSS files are now importable in host apps — a `kiso:palettes` rake task generates CSS stubs so `@import "../builds/tailwind/kiso/palettes/blue.css"` resolves correctly
|
|
27
|
+
|
|
10
28
|
## [0.4.0.pre] - 2026-03-08
|
|
11
29
|
|
|
12
30
|
### Added
|
|
@@ -100,7 +118,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
100
118
|
- Lookbook component previews
|
|
101
119
|
- Bridgetown documentation site
|
|
102
120
|
|
|
103
|
-
[Unreleased]: https://github.com/steveclarke/kiso/compare/v0.4.
|
|
121
|
+
[Unreleased]: https://github.com/steveclarke/kiso/compare/v0.4.2.pre...HEAD
|
|
122
|
+
[0.4.2.pre]: https://github.com/steveclarke/kiso/releases/tag/v0.4.2.pre
|
|
123
|
+
[0.4.1.pre]: https://github.com/steveclarke/kiso/releases/tag/v0.4.1.pre
|
|
104
124
|
[0.4.0.pre]: https://github.com/steveclarke/kiso/releases/tag/v0.4.0.pre
|
|
105
125
|
[0.3.0.pre]: https://github.com/steveclarke/kiso/releases/tag/v0.3.0.pre
|
|
106
126
|
[0.2.2.pre]: https://github.com/steveclarke/kiso/releases/tag/v0.2.2.pre
|
|
@@ -51,29 +51,40 @@
|
|
|
51
51
|
Purpose-named tokens that flip in dark mode. Components use bg-primary,
|
|
52
52
|
text-foreground, etc. — never raw palette shades or dark: prefixes.
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
Two ways to customize brand colors:
|
|
55
|
+
|
|
56
|
+
1. Define a shade scale (Tailwind-native):
|
|
57
|
+
@theme {
|
|
58
|
+
--color-primary-50: oklch(...);
|
|
59
|
+
--color-primary-500: oklch(...);
|
|
60
|
+
--color-primary-950: oklch(...);
|
|
61
|
+
}
|
|
62
|
+
Kiso auto-wires: shade 500 for light mode, shade 400 for dark mode,
|
|
63
|
+
shade 50 for foreground (light), shade 950 for foreground (dark).
|
|
64
|
+
|
|
65
|
+
2. Override the semantic token directly:
|
|
66
|
+
@theme { --color-primary: oklch(0.55 0.10 237); }
|
|
56
67
|
*/
|
|
57
68
|
|
|
58
69
|
@theme {
|
|
59
|
-
/* Brand / action colors */
|
|
60
|
-
--color-primary: var(--color-rose-500);
|
|
61
|
-
--color-primary-foreground: white;
|
|
70
|
+
/* Brand / action colors — auto-wire from shade scale, fall back to defaults */
|
|
71
|
+
--color-primary: var(--color-primary-500, var(--color-rose-500));
|
|
72
|
+
--color-primary-foreground: var(--color-primary-50, white);
|
|
62
73
|
|
|
63
|
-
--color-secondary: var(--color-teal-600);
|
|
64
|
-
--color-secondary-foreground: white;
|
|
74
|
+
--color-secondary: var(--color-secondary-500, var(--color-teal-600));
|
|
75
|
+
--color-secondary-foreground: var(--color-secondary-50, white);
|
|
65
76
|
|
|
66
|
-
--color-success: var(--color-green-600);
|
|
67
|
-
--color-success-foreground: white;
|
|
77
|
+
--color-success: var(--color-success-500, var(--color-green-600));
|
|
78
|
+
--color-success-foreground: var(--color-success-50, white);
|
|
68
79
|
|
|
69
|
-
--color-info: var(--color-sky-600);
|
|
70
|
-
--color-info-foreground: white;
|
|
80
|
+
--color-info: var(--color-info-500, var(--color-sky-600));
|
|
81
|
+
--color-info-foreground: var(--color-info-50, white);
|
|
71
82
|
|
|
72
|
-
--color-warning: var(--color-amber-500);
|
|
73
|
-
--color-warning-foreground: var(--color-amber-950);
|
|
83
|
+
--color-warning: var(--color-warning-500, var(--color-amber-500));
|
|
84
|
+
--color-warning-foreground: var(--color-warning-950, var(--color-amber-950));
|
|
74
85
|
|
|
75
|
-
--color-error: var(--color-red-600);
|
|
76
|
-
--color-error-foreground: white;
|
|
86
|
+
--color-error: var(--color-error-500, var(--color-red-600));
|
|
87
|
+
--color-error-foreground: var(--color-error-50, white);
|
|
77
88
|
|
|
78
89
|
/* Surface tokens */
|
|
79
90
|
--color-background: white;
|
|
@@ -100,23 +111,23 @@
|
|
|
100
111
|
Redefine tokens under .dark — components never use dark: prefixes. */
|
|
101
112
|
|
|
102
113
|
.dark {
|
|
103
|
-
--color-primary: var(--color-rose-400);
|
|
104
|
-
--color-primary-foreground: var(--color-zinc-950);
|
|
114
|
+
--color-primary: var(--color-primary-400, var(--color-rose-400));
|
|
115
|
+
--color-primary-foreground: var(--color-primary-950, var(--color-zinc-950));
|
|
105
116
|
|
|
106
|
-
--color-secondary: var(--color-teal-400);
|
|
107
|
-
--color-secondary-foreground: var(--color-zinc-950);
|
|
117
|
+
--color-secondary: var(--color-secondary-400, var(--color-teal-400));
|
|
118
|
+
--color-secondary-foreground: var(--color-secondary-950, var(--color-zinc-950));
|
|
108
119
|
|
|
109
|
-
--color-success: var(--color-green-400);
|
|
110
|
-
--color-success-foreground: var(--color-zinc-950);
|
|
120
|
+
--color-success: var(--color-success-400, var(--color-green-400));
|
|
121
|
+
--color-success-foreground: var(--color-success-950, var(--color-zinc-950));
|
|
111
122
|
|
|
112
|
-
--color-info: var(--color-sky-400);
|
|
113
|
-
--color-info-foreground: var(--color-zinc-950);
|
|
123
|
+
--color-info: var(--color-info-400, var(--color-sky-400));
|
|
124
|
+
--color-info-foreground: var(--color-info-950, var(--color-zinc-950));
|
|
114
125
|
|
|
115
|
-
--color-warning: var(--color-amber-400);
|
|
116
|
-
--color-warning-foreground: var(--color-zinc-950);
|
|
126
|
+
--color-warning: var(--color-warning-400, var(--color-amber-400));
|
|
127
|
+
--color-warning-foreground: var(--color-warning-950, var(--color-zinc-950));
|
|
117
128
|
|
|
118
|
-
--color-error: var(--color-red-400);
|
|
119
|
-
--color-error-foreground: var(--color-zinc-950);
|
|
129
|
+
--color-error: var(--color-error-400, var(--color-red-400));
|
|
130
|
+
--color-error-foreground: var(--color-error-950, var(--color-zinc-950));
|
|
120
131
|
|
|
121
132
|
--color-background: var(--color-zinc-950);
|
|
122
133
|
--color-foreground: var(--color-zinc-50);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Based on shadcn/ui's Blue theme with OKLCH color values.
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
6
|
-
1. Import in your CSS: @import "kiso/palettes/blue.css";
|
|
6
|
+
1. Import in your CSS: @import "../builds/tailwind/kiso/palettes/blue.css";
|
|
7
7
|
2. Add to your HTML: <html data-palette="blue"> or <body data-palette="blue">
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Based on shadcn/ui's Green theme with OKLCH color values.
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
6
|
-
1. Import in your CSS: @import "kiso/palettes/green.css";
|
|
6
|
+
1. Import in your CSS: @import "../builds/tailwind/kiso/palettes/green.css";
|
|
7
7
|
2. Add to your HTML: <html data-palette="green"> or <body data-palette="green">
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Based on shadcn/ui's Orange theme with OKLCH color values.
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
6
|
-
1. Import in your CSS: @import "kiso/palettes/orange.css";
|
|
6
|
+
1. Import in your CSS: @import "../builds/tailwind/kiso/palettes/orange.css";
|
|
7
7
|
2. Add to your HTML: <html data-palette="orange"> or <body data-palette="orange">
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Based on shadcn/ui's Violet theme with OKLCH color values.
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
6
|
-
1. Import in your CSS: @import "kiso/palettes/violet.css";
|
|
6
|
+
1. Import in your CSS: @import "../builds/tailwind/kiso/palettes/violet.css";
|
|
7
7
|
2. Add to your HTML: <html data-palette="violet"> or <body data-palette="violet">
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Based on shadcn/ui's Zinc theme with OKLCH color values.
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
6
|
-
1. Import in your CSS: @import "kiso/palettes/zinc.css";
|
|
6
|
+
1. Import in your CSS: @import "../builds/tailwind/kiso/palettes/zinc.css";
|
|
7
7
|
2. Add to your HTML: <html data-palette="zinc"> or <body data-palette="zinc">
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -22,6 +22,9 @@ module Kiso
|
|
|
22
22
|
# inherit overrides automatically. For self-rendering components, the hash is
|
|
23
23
|
# also passed as a local so the partial can apply overrides to internally
|
|
24
24
|
# rendered elements.
|
|
25
|
+
# @param scope [Hash, nil] domain locals shared from parent to sub-parts via context stack.
|
|
26
|
+
# Sub-parts receive scope values as kwargs automatically. Explicit kwargs on sub-part
|
|
27
|
+
# calls override scope values. One level deep only — no ancestor resolution.
|
|
25
28
|
# @param kwargs [Hash] locals passed to the partial (e.g. +css_classes:+)
|
|
26
29
|
# @yield optional block for component content
|
|
27
30
|
# @return [ActiveSupport::SafeBuffer] rendered HTML
|
|
@@ -39,15 +42,31 @@ module Kiso
|
|
|
39
42
|
# appui(:pricing_card, :header) { "Header" }
|
|
40
43
|
# end
|
|
41
44
|
#
|
|
45
|
+
# @example Share domain locals with sub-parts
|
|
46
|
+
# appui(:room_card, scope: { room: room }) do
|
|
47
|
+
# appui(:room_card, :status)
|
|
48
|
+
# appui(:room_card, :meta)
|
|
49
|
+
# end
|
|
50
|
+
#
|
|
42
51
|
# @example Render a collection
|
|
43
52
|
# appui(:pricing_card, collection: @plans)
|
|
44
|
-
def appui(component, part = nil, collection: nil, ui: nil, **kwargs, &block)
|
|
53
|
+
def appui(component, part = nil, collection: nil, ui: nil, scope: nil, **kwargs, &block)
|
|
45
54
|
kiso_render_component(
|
|
46
55
|
component, part,
|
|
47
56
|
path_prefix: "components",
|
|
48
|
-
collection: collection, ui: ui, merge_global_ui: false,
|
|
57
|
+
collection: collection, ui: ui, scope: scope, merge_global_ui: false,
|
|
49
58
|
**kwargs, &block
|
|
50
59
|
)
|
|
51
60
|
end
|
|
61
|
+
|
|
62
|
+
# Renders a themed HTML element for host app components.
|
|
63
|
+
#
|
|
64
|
+
# Identical to {ComponentHelper#kui_tag} — provided as a naming
|
|
65
|
+
# convenience so host app partials use +appui_tag+ alongside +appui()+.
|
|
66
|
+
#
|
|
67
|
+
# @see ComponentHelper#kui_tag
|
|
68
|
+
def appui_tag(...)
|
|
69
|
+
kui_tag(...)
|
|
70
|
+
end
|
|
52
71
|
end
|
|
53
72
|
end
|
|
@@ -16,6 +16,9 @@ module Kiso
|
|
|
16
16
|
# inherit overrides automatically. For self-rendering components, the hash is
|
|
17
17
|
# also passed as a local so the partial can apply overrides to internally
|
|
18
18
|
# rendered elements.
|
|
19
|
+
# @param scope [Hash, nil] domain locals shared from parent to sub-parts via context stack.
|
|
20
|
+
# Sub-parts receive scope values as kwargs automatically. Explicit kwargs on sub-part
|
|
21
|
+
# calls override scope values. One level deep only — no ancestor resolution.
|
|
19
22
|
# @param kwargs [Hash] locals passed to the partial (e.g. +color:+, +variant:+, +css_classes:+)
|
|
20
23
|
# @yield optional block for component content
|
|
21
24
|
# @return [ActiveSupport::SafeBuffer] rendered HTML
|
|
@@ -33,13 +36,18 @@ module Kiso
|
|
|
33
36
|
# @example Render an alert with inner element overrides
|
|
34
37
|
# kui(:alert, icon: "info", ui: { close: "opacity-50" })
|
|
35
38
|
#
|
|
39
|
+
# @example Share domain locals with sub-parts
|
|
40
|
+
# kui(:card, scope: { project: @project }) do
|
|
41
|
+
# kui(:card, :header) # sub-part receives project: automatically
|
|
42
|
+
# end
|
|
43
|
+
#
|
|
36
44
|
# @example Render a collection
|
|
37
45
|
# kui(:badge, collection: @tags)
|
|
38
|
-
def kui(component, part = nil, collection: nil, ui: nil, **kwargs, &block)
|
|
46
|
+
def kui(component, part = nil, collection: nil, ui: nil, scope: nil, **kwargs, &block)
|
|
39
47
|
kiso_render_component(
|
|
40
48
|
component, part,
|
|
41
49
|
path_prefix: "kiso/components",
|
|
42
|
-
collection: collection, ui: ui, merge_global_ui: true,
|
|
50
|
+
collection: collection, ui: ui, scope: scope, merge_global_ui: true,
|
|
43
51
|
**kwargs, &block
|
|
44
52
|
)
|
|
45
53
|
end
|
|
@@ -70,6 +78,36 @@ module Kiso
|
|
|
70
78
|
(component_options.delete(:data) || {}).merge(slot: slot, **data_attrs)
|
|
71
79
|
end
|
|
72
80
|
|
|
81
|
+
# Renders a themed HTML element with Kiso conventions.
|
|
82
|
+
#
|
|
83
|
+
# Collapses the common +content_tag+ + +kiso_prepare_options+ + theme
|
|
84
|
+
# rendering boilerplate into a single call. Use in component partials
|
|
85
|
+
# instead of manually wiring +content_tag+.
|
|
86
|
+
#
|
|
87
|
+
# @param tag [Symbol] HTML element name (e.g. +:div+, +:span+, +:button+)
|
|
88
|
+
# @param theme [ClassVariants::Instance] the theme module to render classes from
|
|
89
|
+
# @param slot [String] the +data-slot+ value (kebab-case)
|
|
90
|
+
# @param css_classes [String] caller's class overrides, merged via +tailwind_merge+
|
|
91
|
+
# @param variants [Hash] variant values forwarded to +theme.render+
|
|
92
|
+
# (e.g. +{ size: :md, color: :primary }+)
|
|
93
|
+
# @param component_options [Hash] HTML attributes forwarded to +content_tag+
|
|
94
|
+
# (e.g. +id:+, +aria:+). A +data:+ key is extracted and merged with slot.
|
|
95
|
+
# @yield optional block for element content
|
|
96
|
+
# @return [ActiveSupport::SafeBuffer] rendered HTML
|
|
97
|
+
#
|
|
98
|
+
# @example In a component partial
|
|
99
|
+
# kui_tag :div, theme: Kiso::Themes::Badge, slot: "badge",
|
|
100
|
+
# css_classes: css_classes, variants: { color: color, variant: variant },
|
|
101
|
+
# **component_options do
|
|
102
|
+
# yield
|
|
103
|
+
# end
|
|
104
|
+
def kui_tag(tag, theme:, slot:, css_classes: "", variants: {}, **component_options, &block)
|
|
105
|
+
content_tag(tag,
|
|
106
|
+
class: theme.render(**variants, class: css_classes),
|
|
107
|
+
data: kiso_prepare_options(component_options, slot: slot),
|
|
108
|
+
**component_options, &block)
|
|
109
|
+
end
|
|
110
|
+
|
|
73
111
|
private
|
|
74
112
|
|
|
75
113
|
# Shared rendering pipeline for both kui() and appui().
|
|
@@ -79,11 +117,12 @@ module Kiso
|
|
|
79
117
|
# @param path_prefix [String] partial path prefix (e.g. "kiso/components" or "components")
|
|
80
118
|
# @param collection [Array, nil] renders the partial once per item when present
|
|
81
119
|
# @param ui [Hash, nil] per-slot class overrides
|
|
120
|
+
# @param scope [Hash, nil] domain locals shared from parent to sub-parts
|
|
82
121
|
# @param merge_global_ui [Boolean] whether to merge global config ui layer
|
|
83
122
|
# @param kwargs [Hash] locals passed to the partial
|
|
84
123
|
# @param block [Proc] optional block for component content
|
|
85
124
|
# @return [ActiveSupport::SafeBuffer] rendered HTML
|
|
86
|
-
def kiso_render_component(component, part, path_prefix:, collection:, ui:, merge_global_ui: true, **kwargs, &block)
|
|
125
|
+
def kiso_render_component(component, part, path_prefix:, collection:, ui:, scope:, merge_global_ui: true, **kwargs, &block)
|
|
87
126
|
path = if part
|
|
88
127
|
"#{path_prefix}/#{component}/#{part}"
|
|
89
128
|
else
|
|
@@ -101,6 +140,10 @@ module Kiso
|
|
|
101
140
|
block ||= proc {}
|
|
102
141
|
|
|
103
142
|
if part
|
|
143
|
+
# Sub-part: merge scope from parent context (scope values first, explicit kwargs win)
|
|
144
|
+
parent_scope = kiso_current_scope(component)
|
|
145
|
+
kwargs = parent_scope.merge(kwargs) if parent_scope.present?
|
|
146
|
+
|
|
104
147
|
# Sub-part: merge slot override from parent's ui context
|
|
105
148
|
parent_ui = kiso_current_ui(component)
|
|
106
149
|
if (slot_classes = parent_ui[part].presence)
|
|
@@ -124,9 +167,11 @@ module Kiso
|
|
|
124
167
|
ui || {}
|
|
125
168
|
end
|
|
126
169
|
has_ui = merged_ui.present?
|
|
170
|
+
has_scope = scope.present?
|
|
127
171
|
|
|
128
172
|
# Push context for composed sub-parts to read (skip when empty)
|
|
129
173
|
kiso_push_ui_context(component, merged_ui) if has_ui
|
|
174
|
+
kiso_push_scope(component, scope) if has_scope
|
|
130
175
|
begin
|
|
131
176
|
locals = has_ui ? kwargs.merge(ui: merged_ui) : kwargs
|
|
132
177
|
|
|
@@ -137,6 +182,7 @@ module Kiso
|
|
|
137
182
|
end
|
|
138
183
|
ensure
|
|
139
184
|
kiso_pop_ui_context(component) if has_ui
|
|
185
|
+
kiso_pop_scope(component) if has_scope
|
|
140
186
|
end
|
|
141
187
|
end
|
|
142
188
|
end
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Kiso
|
|
4
|
-
# Manages
|
|
4
|
+
# Manages request-scoped context stacks for component communication.
|
|
5
5
|
#
|
|
6
|
-
# This is ERB's equivalent of Vue's provide/inject pattern.
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
6
|
+
# This is ERB's equivalent of Vue's provide/inject pattern. Two stacks:
|
|
7
|
+
#
|
|
8
|
+
# - **ui:** — per-slot CSS class overrides. When a parent component is
|
|
9
|
+
# rendered with +ui:+, the hash is pushed onto a stack. Sub-parts read
|
|
10
|
+
# their slot override automatically.
|
|
11
|
+
# - **scope:** — domain locals shared from parent to sub-parts. When a
|
|
12
|
+
# parent is rendered with +scope:+, the hash is pushed onto a stack.
|
|
13
|
+
# Sub-parts receive scope values as kwargs, with explicit kwargs
|
|
14
|
+
# taking priority. One level deep only — no ancestor resolution.
|
|
10
15
|
#
|
|
11
16
|
# Thread-safe because Rails creates a fresh view context (and therefore
|
|
12
17
|
# fresh instance variables) per request.
|
|
13
18
|
#
|
|
14
|
-
# @example
|
|
19
|
+
# @example ui: stack flow
|
|
15
20
|
# # Parent pushes:
|
|
16
21
|
# kiso_push_ui_context(:card, { header: "p-8", title: "text-xl" })
|
|
17
22
|
#
|
|
@@ -21,6 +26,16 @@ module Kiso
|
|
|
21
26
|
# # After parent renders:
|
|
22
27
|
# kiso_pop_ui_context(:card)
|
|
23
28
|
#
|
|
29
|
+
# @example scope: stack flow
|
|
30
|
+
# # Parent pushes:
|
|
31
|
+
# kiso_push_scope(:room_card, { room: room })
|
|
32
|
+
#
|
|
33
|
+
# # Sub-part reads (merged into kwargs before render):
|
|
34
|
+
# kiso_current_scope(:room_card) #=> { room: room }
|
|
35
|
+
#
|
|
36
|
+
# # After parent renders:
|
|
37
|
+
# kiso_pop_scope(:room_card)
|
|
38
|
+
#
|
|
24
39
|
# @see ComponentHelper#kui
|
|
25
40
|
module UiContextHelper
|
|
26
41
|
# Push a ui hash onto the context stack for a component.
|
|
@@ -49,11 +64,45 @@ module Kiso
|
|
|
49
64
|
kiso_ui_stack.dig(component, -1) || {}
|
|
50
65
|
end
|
|
51
66
|
|
|
67
|
+
# Push a scope hash onto the context stack for a component.
|
|
68
|
+
#
|
|
69
|
+
# Scope shares domain locals from a parent component with its sub-parts
|
|
70
|
+
# so callers don't have to repeat the same locals on every sub-part call.
|
|
71
|
+
#
|
|
72
|
+
# @param component [Symbol] the component name (e.g. +:room_card+)
|
|
73
|
+
# @param scope [Hash] domain locals to share with sub-parts
|
|
74
|
+
# @return [void]
|
|
75
|
+
def kiso_push_scope(component, scope)
|
|
76
|
+
kiso_scope_stack[component] ||= []
|
|
77
|
+
kiso_scope_stack[component].push(scope || {})
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Pop the most recent scope hash for a component.
|
|
81
|
+
#
|
|
82
|
+
# @param component [Symbol] the component name
|
|
83
|
+
# @return [Hash, nil] the popped scope hash
|
|
84
|
+
def kiso_pop_scope(component)
|
|
85
|
+
kiso_scope_stack[component]&.pop
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Read the current scope hash for a component (top of stack).
|
|
89
|
+
#
|
|
90
|
+
# @param component [Symbol] the component name
|
|
91
|
+
# @return [Hash] the current scope, or empty hash
|
|
92
|
+
def kiso_current_scope(component)
|
|
93
|
+
kiso_scope_stack.dig(component, -1) || {}
|
|
94
|
+
end
|
|
95
|
+
|
|
52
96
|
private
|
|
53
97
|
|
|
54
|
-
# @return [Hash{Symbol => Array<Hash>}] per-component stacks
|
|
98
|
+
# @return [Hash{Symbol => Array<Hash>}] per-component ui stacks
|
|
55
99
|
def kiso_ui_stack
|
|
56
100
|
@kiso_ui_stack ||= {}
|
|
57
101
|
end
|
|
102
|
+
|
|
103
|
+
# @return [Hash{Symbol => Array<Hash>}] per-component scope stacks
|
|
104
|
+
def kiso_scope_stack
|
|
105
|
+
@kiso_scope_stack ||= {}
|
|
106
|
+
end
|
|
58
107
|
end
|
|
59
108
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
<%# locals: (css_classes: "", **component_options) %>
|
|
1
|
+
<%# locals: (center: false, css_classes: "", **component_options) %>
|
|
2
2
|
<%= content_tag :div,
|
|
3
|
-
class: Kiso::Themes::App.render(class: css_classes),
|
|
3
|
+
class: Kiso::Themes::App.render(center: center, class: css_classes),
|
|
4
4
|
data: kiso_prepare_options(component_options, slot: "app"),
|
|
5
5
|
**component_options do %>
|
|
6
6
|
<%= yield %>
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
<%% # locals: (css_classes: "", **component_options) %>
|
|
2
|
-
<%%=
|
|
3
|
-
|
|
4
|
-
data: kiso_prepare_options(component_options, slot: "<%= slot_name %>"),
|
|
5
|
-
**component_options do %>
|
|
2
|
+
<%%= appui_tag :div, theme: AppThemes::<%= has_namespace? ? "#{module_prefix}::" : "" %><%= class_name_without_namespace %>, slot: "<%= slot_name %>",
|
|
3
|
+
css_classes: css_classes, **component_options do %>
|
|
6
4
|
<%%= yield %>
|
|
7
5
|
<%% end %>
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
<%% # locals: (css_classes: "", **component_options) %>
|
|
2
|
-
<%%=
|
|
3
|
-
|
|
4
|
-
data: kiso_prepare_options(component_options, slot: "<%= sub_part_slot_name %>"),
|
|
5
|
-
**component_options do %>
|
|
2
|
+
<%%= appui_tag :div, theme: AppThemes::<%= has_namespace? ? "#{module_prefix}::" : "" %><%= sub_part_class_name %>, slot: "<%= sub_part_slot_name %>",
|
|
3
|
+
css_classes: css_classes, **component_options do %>
|
|
6
4
|
<%%= yield %>
|
|
7
5
|
<%% end %>
|
data/lib/kiso/engine.rb
CHANGED
|
@@ -10,6 +10,10 @@ module Kiso
|
|
|
10
10
|
class Engine < ::Rails::Engine
|
|
11
11
|
isolate_namespace Kiso
|
|
12
12
|
|
|
13
|
+
rake_tasks do
|
|
14
|
+
load Kiso::Engine.root.join("lib/tasks/kiso.rake")
|
|
15
|
+
end
|
|
16
|
+
|
|
13
17
|
# Loads Kiso's locale files so host apps can override translations.
|
|
14
18
|
initializer "kiso.i18n" do
|
|
15
19
|
config.i18n.load_path += Dir[root.join("config/locales/**/*.yml")]
|
data/lib/kiso/themes/layout.rb
CHANGED
|
@@ -5,10 +5,19 @@ module Kiso
|
|
|
5
5
|
#
|
|
6
6
|
# @example
|
|
7
7
|
# App.render
|
|
8
|
+
# App.render(center: true)
|
|
8
9
|
#
|
|
9
|
-
#
|
|
10
|
+
# Variants:
|
|
11
|
+
# - +center+ — centers content vertically and horizontally (e.g., login pages)
|
|
10
12
|
App = ClassVariants.build(
|
|
11
|
-
base: "bg-background text-foreground antialiased"
|
|
13
|
+
base: "bg-background text-foreground antialiased",
|
|
14
|
+
variants: {
|
|
15
|
+
center: {
|
|
16
|
+
true => "min-h-screen flex items-center justify-center",
|
|
17
|
+
false => ""
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
defaults: {center: false}
|
|
12
21
|
)
|
|
13
22
|
|
|
14
23
|
# Content containment with consistent max-width and padding.
|
data/lib/kiso/version.rb
CHANGED
data/lib/tasks/kiso.rake
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Generates CSS stub files for Kiso's palette files in the host app.
|
|
2
|
+
#
|
|
3
|
+
# tailwindcss-rails creates a stub at app/assets/builds/tailwind/kiso.css
|
|
4
|
+
# for engine.css, but it doesn't handle subdirectories. Palette files at
|
|
5
|
+
# app/assets/tailwind/kiso/palettes/*.css inside the gem are invisible to
|
|
6
|
+
# the host app's Tailwind CLI without stubs.
|
|
7
|
+
#
|
|
8
|
+
# This task creates matching stubs so host apps can import palettes with:
|
|
9
|
+
# @import "../builds/tailwind/kiso/palettes/blue.css";
|
|
10
|
+
|
|
11
|
+
namespace :kiso do
|
|
12
|
+
desc "Generate CSS stubs for Kiso palette files"
|
|
13
|
+
task palettes: :environment do
|
|
14
|
+
palette_dir = Kiso::Engine.root.join("app/assets/tailwind/kiso/palettes")
|
|
15
|
+
next unless palette_dir.directory?
|
|
16
|
+
|
|
17
|
+
output_dir = Rails.root.join("app/assets/builds/tailwind/kiso/palettes")
|
|
18
|
+
FileUtils.mkdir_p(output_dir)
|
|
19
|
+
|
|
20
|
+
Dir[palette_dir.join("*.css")].each do |source|
|
|
21
|
+
name = File.basename(source)
|
|
22
|
+
stub_path = output_dir.join(name)
|
|
23
|
+
File.write(stub_path, <<~CSS)
|
|
24
|
+
/* DO NOT MODIFY THIS FILE, it was auto-generated by kiso */
|
|
25
|
+
|
|
26
|
+
@import "#{source}";
|
|
27
|
+
CSS
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Hook into tailwindcss-rails build pipeline so palette stubs are
|
|
33
|
+
# generated before the Tailwind CLI runs.
|
|
34
|
+
if Rake::Task.task_defined?("tailwindcss:engines")
|
|
35
|
+
Rake::Task["tailwindcss:engines"].enhance(["kiso:palettes"])
|
|
36
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kiso
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.2.pre
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steve Clarke
|
|
@@ -387,6 +387,7 @@ files:
|
|
|
387
387
|
- lib/kiso/themes/toggle.rb
|
|
388
388
|
- lib/kiso/themes/toggle_group.rb
|
|
389
389
|
- lib/kiso/version.rb
|
|
390
|
+
- lib/tasks/kiso.rake
|
|
390
391
|
homepage: https://github.com/steveclarke/kiso
|
|
391
392
|
licenses:
|
|
392
393
|
- MIT
|