keystone_ui-preferences 0.8.0 → 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.
- checksums.yaml +4 -4
- data/README.md +19 -9
- data/app/javascript/keystone_ui/preferences/appearance_editor_controller.js +235 -0
- data/app/models/keystone_ui/preferences/theme_roles.rb +25 -0
- data/app/views/keystone_ui/preferences/settings/_account_appearance.html.erb +15 -3
- data/app/views/keystone_ui/preferences/settings/_appearance.html.erb +30 -18
- data/app/views/keystone_ui/preferences/settings/_colour_choices.html.erb +15 -12
- data/app/views/keystone_ui/preferences/settings/_editor_layout.html.erb +29 -0
- data/app/views/keystone_ui/preferences/settings/_theme_preview.html.erb +34 -0
- data/app/views/keystone_ui/preferences/settings/_theme_settings.html.erb +49 -14
- data/lib/generators/keystone_ui/preferences/install/install_generator.rb +4 -4
- data/lib/generators/keystone_ui/preferences/update/update_generator.rb +4 -4
- data/lib/keystone_ui/preferences/version.rb +1 -1
- metadata +8 -6
- data/app/javascript/keystone_ui/preferences/theme_settings_controller.js +0 -84
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e09ee48853d6dd4eae14eb48ac7686dc6c4329e329cecbd199f7e53e13aa8001
|
|
4
|
+
data.tar.gz: 95ff23cb290be1c1ec798f26dff2c88c7ffa321424f811693697a6fed46d732e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe83084aafb891f389bbd94524e7c257c69d375f8009835fd6492e8e855c41d50f2625a09467f48de25f70adb47d7a9505c37fd6997d223255ca8a0a467c8cf1
|
|
7
|
+
data.tar.gz: 15825f59455347b377c02e1a82092e02789141969664410da902db37386547fed82c47e3c9da22656e754bf45562433382ce3103b1fb4f01a2430b63f08b42a9
|
data/README.md
CHANGED
|
@@ -6,7 +6,7 @@ A page gives a `ui_data_table` a `key:`. This gem saves each signed-in person's
|
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
|
-
Add the gem and run its install generator, which copies a migration for its table and the
|
|
9
|
+
Add the gem and run its install generator, which copies a migration for its table and the appearance editor script the Appearance sections use:
|
|
10
10
|
|
|
11
11
|
```ruby
|
|
12
12
|
gem "keystone_ui-preferences"
|
|
@@ -18,20 +18,22 @@ bin/rails generate keystone_ui:preferences:install
|
|
|
18
18
|
bin/rails db:migrate
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
The script lands at `app/javascript/controllers/keystone_ui/preferences/
|
|
21
|
+
The script lands at `app/javascript/controllers/keystone_ui/preferences/appearance_editor_controller.js`. Register it in `app/javascript/controllers/index.js`:
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
|
-
import
|
|
25
|
-
application.register("keystone-ui--preferences--
|
|
24
|
+
import AppearanceEditorController from "./keystone_ui/preferences/appearance_editor_controller"
|
|
25
|
+
application.register("keystone-ui--preferences--appearance-editor", AppearanceEditorController)
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
After updating the gem, run its update generator to copy any migrations added since it was installed, and the
|
|
28
|
+
After updating the gem, run its update generator to copy any migrations added since it was installed, and the appearance editor script when the app does not have it yet:
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
31
|
bin/rails generate keystone_ui:preferences:update
|
|
32
32
|
bin/rails db:migrate
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
An app that installed an earlier version has a template picker script at `app/javascript/controllers/keystone_ui/preferences/theme_settings_controller.js` and a theme editor script at `app/javascript/controllers/keystone_ui/preferences/theme_editor_controller.js`. The appearance editor script replaces both. Register the appearance editor script as shown above. Then remove both old scripts and the two lines in `app/javascript/controllers/index.js` that register them as `keystone-ui--preferences--theme-settings` and `keystone-ui--preferences--theme-editor`. The update generator copies the new script and leaves both old scripts in place, so removing them is the app's own step.
|
|
36
|
+
|
|
35
37
|
Mount the engine in `config/routes.rb`. A table's Columns menu saves to it:
|
|
36
38
|
|
|
37
39
|
```ruby
|
|
@@ -182,7 +184,7 @@ SettingsHub.section :appearance, area: :user, title: "Appearance",
|
|
|
182
184
|
runs: "KeystoneUi::Preferences::PickAppearance"
|
|
183
185
|
```
|
|
184
186
|
|
|
185
|
-
The section looks and behaves as keystone_ui-colors' colour settings do. It offers Default, the five named templates from keystone_ui-looks, the six preset themes from keystone_ui-looks and Custom, with an accent, a surface and a text colour picker under them. The person's own saved choice is selected, or Default when they have none, and the pickers show the colours drawn for them now. Picking a template sets the pickers to that template's colours at once, and changing a picker selects Custom, through the
|
|
187
|
+
The section looks and behaves as keystone_ui-colors' colour settings do. It offers Default, the five named templates from keystone_ui-looks, the six preset themes from keystone_ui-looks and Custom, with an accent, a surface and a text colour picker under them. The person's own saved choice is selected, or Default when they have none, and the pickers show the colours drawn for them now. Picking a template sets the pickers to that template's colours at once, and changing a picker selects Custom, through the appearance editor script the install generator copies. Without the script the section still saves, and the form saves with a full page load, so it works in a Hotwire Native web view.
|
|
186
188
|
|
|
187
189
|
Saving a template keeps `{ "template_name": "forest" }` for that person under the `colours` key. Saving a preset theme keeps only its name, as `{ "preset_name": "harbor" }`. Saving Custom keeps `{ "accent": "#e11d48", "surface": "#f5e6c8", "text": "#3b2f1e" }`. Saving Default removes the person's `colours` row, so the account's colours, or the app's defaults, apply again. The next page the person opens is drawn in the saved colours.
|
|
188
190
|
|
|
@@ -196,9 +198,17 @@ Shape and type settings are kept from the `:root` block only, as `{ "radius": {
|
|
|
196
198
|
|
|
197
199
|
Each refusal below saves nothing and says why. A paste over 20,000 characters is refused before any of it is read. A paste containing `url(` or `@import` anywhere is refused. A paste with no shadcn colour role in a `:root` or `.dark` block is refused. A colour that fails the check is refused with a message naming the role and whether it is the light or dark value. A shape or type value that fails its check is refused with a message naming the setting, and so is a font list left with no font the app offers. A paste is refused with the same message as other colours while the account sets the colours for everyone.
|
|
198
200
|
|
|
199
|
-
|
|
201
|
+
After Look and Mode, the section lists every theme setting as its own field, named by its shadcn variable, with no closed disclosure around them. The fields are grouped as tweakcn's editor groups them. Colors holds the colour roles in sets, each with its foreground beside it: Page (`background` and `foreground`), Primary, Secondary, Accent, Muted, Card, Popover, Destructive, Border, input and ring, Chart (`chart-1` to `chart-5`) and the eight Sidebar roles. Typography holds the sans, serif, mono and heading fonts, the four font weights and the letter spacing. Other holds the radius, the spacing, the border width and the six shadow settings. Each colour role has a light and a dark keystone_ui colour picker side by side, and the shadow colour has one, so a colour can be typed as hex, `rgb()`, `hsl()` or `oklch()`. Every other setting is a text field. Each font field suggests the fonts in `theme_fonts` and then the system fonts the gem offers, and still takes a typed list of several fonts. The fields show the person's saved theme, so after a paste they hold the values that were read. Changing a field and pressing Save saves the fields as the person's theme, so a theme edited by hand stays the person's own. A field left blank leaves that setting out of the theme. Each value is checked and refused exactly as a pasted one is, with spaces around it removed first. The fields are saved only when they differ from the saved theme, so picking a template or changing the Accent, Surface or Text picker saves as before, and a paste sent in the same save wins over the fields. The grouped fields and the font suggestions need no script, but the colour pickers need keystone_ui's colour picker script to take a typed colour.
|
|
202
|
+
|
|
203
|
+
Each change to a theme field is drawn on the whole page before saving, through the appearance editor script the install generator copies. The script sets the setting's `--ks-*` variables on the page's root element, taking the list of which setting sets which variables from the same theme roles list the palette style tag writes from, so the page looks as it will after Save. A colour also sets the hover colour the style tag derives from `primary`, `secondary` and `destructive`, and a dark value sets only the `-dark` variables, so it shows only where the page is drawn dark. Colours, corner radius, spacing, border width, letter spacing, fonts, font weights and the shadow are drawn this way, and the shadow is drawn only once all six shadow settings hold a value, as the style tag writes it. A value the browser cannot draw leaves the page as it was, and it is still sent and checked on Save. Leaving the section without saving removes every variable the script set, so the next page, a Turbo visit included, is drawn in the saved theme. The script saves nothing and sends no request, so Save works as before, and without the script the fields still save.
|
|
204
|
+
|
|
205
|
+
Beside the fields the section shows a preview of keystone_ui's own components: a card, a primary, a secondary and a danger button, a form with a text field and a select, a table, a line chart and a sidebar navigation list. The preview is drawn twice, once on a side marked light and once on a side marked dark, from sample data the gem holds. Each unsaved change the appearance editor script draws on the page also shows in the preview, so a dark value changes only the dark side, including while the page itself is drawn dark. A chart colour redraws the preview's line chart and a sidebar colour changes its navigation list. The preview names no font of its own and loads nothing from another site, so it draws in the fonts the theme sets. On a screen 64rem wide or wider the fields and the preview sit side by side. On a narrower screen, such as a phone, the section shows an Edit tab and a Preview tab from keystone_ui's tab switcher, and picking a tab shows its panel through the appearance editor script. The preview needs keystone_ui-styles 0.23.0 or later, whose dark styles leave a side marked light drawn light inside a dark page, and keystone_ui 0.47.0 or later, whose line chart takes light or dark from the side it is drawn on and redraws when the theme's variables change, and it needs keystone_ui's tab switcher and line chart scripts registered. The preview is shown only alongside the theme fields, so it is not shown while the account sets the colours for everyone.
|
|
206
|
+
|
|
207
|
+
The preset themes are option cards after the templates, each showing its light primary and secondary colours as swatches, and the person's saved preset is selected. Picking a preset card fills the theme fields with that preset's values, through the appearance editor script, which draws them on the whole page and the preview before saving, as it draws a field changed by hand. Once a preset is saved the fields show its values. Theme fields sent unchanged, holding the picked or the saved preset's values, save the picked card as before. Changing a field after picking a preset saves the fields as the person's own theme in place of the preset. Without the script, picking a card and pressing Save still saves the preset. A Reset button beside Save fills every theme field, the page and the preview from the picked preset card, or from the saved theme when no preset card is picked, and saves nothing. A setting the saved theme leaves out is emptied, and the page draws it from the saved theme again.
|
|
208
|
+
|
|
209
|
+
Once a theme field differs from the saved theme, or the picked colour card, the Custom accent, surface or text picker, the picked Mode, the picked Look or, in the account's section, either Members choose switch differs from what the page opened with, or the paste box holds text, the appearance editor script asks before the change is lost. The page opens with the saved colour card, colours, Mode, Look and switches selected, after a refused save as well, so picking another and then the saved one again asks nothing. A paste box that is empty or holds only spaces sends nothing to save, so it asks nothing. Following a link out of the section holds the Turbo visit and opens a question on the page, from keystone_ui's modal, offering Leave without saving and Stay. Leave without saving carries on to the page the link was going to, and Stay closes the question. Because the question is part of the page, it shows in a Hotwire Native web view, where Turbo asks the page before it hands a link to the app. Closing or reloading the page asks the browser to show its own leave-page warning, which a Hotwire Native web view does not show. The native back button and tab bar of a Hotwire Native app leave the page without asking it, so they leave with no question, and so does the browser's back button. Saving, resetting to the saved theme, or changing nothing leaves with no question. The question is part of every Appearance section, the person's and the account's, including one that offers no colours. The question needs keystone_ui's modal script registered as `modal`.
|
|
200
210
|
|
|
201
|
-
|
|
211
|
+
After the theme fields an Export text area shows the fields' current values, saved or not, as a `:root` block with every light value and a `.dark` block with every dark value, in shadcn/ui's variable names, which is the shape the paste box reads. The appearance editor script writes it when the section opens and again on each change, in the browser, so it carries unsaved edits. The text area is read-only and has no name, so Save does not send it. A Copy button beside it copies the export through keystone_ui's clipboard script with no request to the server. Where the browser refuses to copy, as a Hotwire Native web view may, the button says to select the text, and the text area can be selected and copied by hand. A value holding a semicolon or a curly brace is left out, so it cannot end its block or add a setting. An exported theme pasted back into the paste box and saved keeps every value it held. Copying needs keystone_ui's clipboard script registered. The export is not offered in keystone's own `--ks-*` variable names.
|
|
202
212
|
|
|
203
213
|
The `colours` key follows the account layouts above. While an account turns off members-choose for it, the section says the account sets the colours for everyone and offers no colours, and a save that sends colours anyway is refused with a message and saves nothing.
|
|
204
214
|
|
|
@@ -239,7 +249,7 @@ SettingsHub.section :account_appearance, area: :account, title: "Appearance",
|
|
|
239
249
|
runs: "KeystoneUi::Preferences::PickAccountAppearance"
|
|
240
250
|
```
|
|
241
251
|
|
|
242
|
-
The section looks and behaves as keystone_ui-colors' account picker does. It offers Default, the five named templates, the six preset themes and Custom with the three colour pickers
|
|
252
|
+
The section looks and behaves as keystone_ui-colors' account picker does. It offers Default, the five named templates, the six preset themes and Custom with the three colour pickers and the paste box the person's section has, then the app's own look and every registered look, with the account's saved choices selected, or Default and the app's own look when it has none. Under them are two switches, one for whether members choose their own colours and one for whether members choose their own look. Both are on until an admin turns them off. The theme fields come last, grouped into Colors, Typography and Other as in the person's section. The section is the same theme editor as the person's. Each change to a field and each picked preset card is drawn on the whole page before saving. The preview sits beside the fields on a wide screen and under Edit and Preview tabs on a phone. A Reset button beside Save fills the fields from the picked preset card, or from the account's saved theme, and saves nothing. The Export text area and its Copy button carry the fields' current values. Leaving the section without saving draws the next page in the admin's own saved theme. While the app turns off account colours the section shows no preview, no tabs and no Reset button.
|
|
243
253
|
|
|
244
254
|
Saving keeps the account's colours under the `colours` key, as `{ "template_name": "forest" }`, `{ "preset_name": "harbor" }`, `{ "accent": "#e11d48", "surface": "#f5e6c8", "text": "#3b2f1e" }` or a pasted or hand-edited theme, and its look under the `look` key, with each switch in that row's `members_choose` column. Saving Default keeps `{ "template_name": "default" }`, and saving the app's own look keeps an empty look, so neither removes the row its switch is on. The colours, a pasted theme, the theme fields and the look pass the same checks as a person's, the theme fields are saved only when they differ from the account's saved theme or the picked or saved preset, and a template, preset, colour, theme value or look that fails one is refused with a message, and nothing is saved. A save with no account is refused too.
|
|
245
255
|
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
|
|
3
|
+
const THEME_FIELD = /^theme\[([^\]]+)\]\[(light|dark)\]$/
|
|
4
|
+
const ENDS_DECLARATION = /[;{}]/
|
|
5
|
+
const QUICK_CHOICES = "[name='template_name'], [name='accent'], [name='surface'], [name='text'], [name='mode'], [name='look'], [name='members_choose'], [name='members_choose_look']"
|
|
6
|
+
const PROPERTY_FOR_KIND = { colour: "color", length: "width", letter_spacing: "letter-spacing", font_list: "font-family", weight: "font-weight" }
|
|
7
|
+
const SHADOW_SETTINGS = ["shadow-offset-x", "shadow-offset-y", "shadow-blur", "shadow-spread", "shadow-color", "shadow-opacity"]
|
|
8
|
+
const SHADOWS = ["--ks-shadow-surface", "--ks-shadow-overlay", "--ks-shadow-menu"]
|
|
9
|
+
|
|
10
|
+
export default class extends Controller {
|
|
11
|
+
static targets = ["accentPicker", "surfacePicker", "textPicker", "customRadio", "templateLabel"]
|
|
12
|
+
|
|
13
|
+
#setVariables = new Set()
|
|
14
|
+
#loadedChoices = []
|
|
15
|
+
#heldUrl = null
|
|
16
|
+
#leaveAllowed = false
|
|
17
|
+
|
|
18
|
+
connect() {
|
|
19
|
+
this.#loadedChoices = this.#quickChoices()
|
|
20
|
+
this.colorPickerTargets().forEach(picker => picker.addEventListener("change", () => this.customColorChanged()))
|
|
21
|
+
this.#writeExport()
|
|
22
|
+
this.#drawUnsavedFields()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
confirmLeave(event) {
|
|
26
|
+
if (!this.#hasUnsavedChanges()) return
|
|
27
|
+
|
|
28
|
+
event.preventDefault()
|
|
29
|
+
this.#heldUrl = event.detail.url
|
|
30
|
+
this.element.querySelector("[data-leave-question] [data-modal-target='backdrop']").classList.remove("hidden")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
warnBeforeUnload(event) {
|
|
34
|
+
if (this.#hasUnsavedChanges()) event.preventDefault()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
save() {
|
|
38
|
+
this.#leaveAllowed = true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
leave() {
|
|
42
|
+
this.#leaveAllowed = true
|
|
43
|
+
this.element.ownerDocument.defaultView.Turbo.visit(this.#heldUrl)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
disconnect() {
|
|
47
|
+
this.#setVariables.forEach(variable => this.#rootStyle().removeProperty(variable))
|
|
48
|
+
this.#setVariables.clear()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
apply({ target: { name, value } }) {
|
|
52
|
+
this.#writeExport()
|
|
53
|
+
const field = name.match(THEME_FIELD)
|
|
54
|
+
if (!field) return
|
|
55
|
+
|
|
56
|
+
const [, role, side] = field
|
|
57
|
+
if (SHADOW_SETTINGS.includes(role)) return this.#drawShadow()
|
|
58
|
+
|
|
59
|
+
const { kind, variables, hover } = this.#roles()[role]
|
|
60
|
+
const suffix = side === "dark" ? "-dark" : ""
|
|
61
|
+
if (value === "") {
|
|
62
|
+
[...variables, hover].filter(Boolean).forEach(variable => this.#remove(`${variable}${suffix}`))
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
if (!CSS.supports(PROPERTY_FOR_KIND[kind], value)) return
|
|
66
|
+
|
|
67
|
+
variables.forEach(variable => this.#set(`${variable}${suffix}`, value))
|
|
68
|
+
if (hover) this.#set(`${hover}${suffix}`, `color-mix(in oklab, ${value} 85%, white)`)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
colorPickerTargets() {
|
|
72
|
+
return [
|
|
73
|
+
this.hasAccentPickerTarget && this.accentPickerTarget,
|
|
74
|
+
this.hasSurfacePickerTarget && this.surfacePickerTarget,
|
|
75
|
+
this.hasTextPickerTarget && this.textPickerTarget
|
|
76
|
+
].filter(Boolean)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
selectTemplate(event) {
|
|
80
|
+
const input = event.currentTarget
|
|
81
|
+
const label = input.closest("[data-template]")
|
|
82
|
+
const accentHex = input.dataset.accentHex
|
|
83
|
+
const surfaceHex = input.dataset.surfaceHex
|
|
84
|
+
const textHex = input.dataset.textHex
|
|
85
|
+
|
|
86
|
+
this.setPickerValue(this.accentPickerTarget, accentHex)
|
|
87
|
+
this.setPickerValue(this.surfacePickerTarget, surfaceHex)
|
|
88
|
+
this.setPickerValue(this.textPickerTarget, textHex)
|
|
89
|
+
|
|
90
|
+
this.highlightTemplate(label.dataset.template)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
selectPreset(event) {
|
|
94
|
+
const input = event.currentTarget
|
|
95
|
+
const theme = JSON.parse(input.dataset.theme)
|
|
96
|
+
|
|
97
|
+
Object.entries(theme).forEach(([role, sides]) => {
|
|
98
|
+
Object.entries(sides).forEach(([side, value]) => this.setThemeField(`theme[${role}][${side}]`, value))
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
this.highlightTemplate(input.closest("[data-template]").dataset.template)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
reset() {
|
|
105
|
+
const preset = this.element.querySelector("input[name='template_name'][data-theme]:checked")
|
|
106
|
+
const theme = JSON.parse(preset ? preset.dataset.theme : this.element.querySelector("[data-saved-theme]").dataset.savedTheme)
|
|
107
|
+
|
|
108
|
+
this.element.querySelectorAll("[name^='theme[']").forEach(({ name }) => {
|
|
109
|
+
const [, role, side] = name.match(THEME_FIELD)
|
|
110
|
+
this.setThemeField(name, theme[role]?.[side] ?? "")
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setThemeField(name, value) {
|
|
115
|
+
const field = this.element.querySelector(`[name="${name}"]`)
|
|
116
|
+
if (!field) return
|
|
117
|
+
|
|
118
|
+
const picker = field.closest("[data-controller~='color-picker']")
|
|
119
|
+
if (picker) {
|
|
120
|
+
this.setPickerValue(picker, value)
|
|
121
|
+
} else {
|
|
122
|
+
field.value = value
|
|
123
|
+
}
|
|
124
|
+
field.dispatchEvent(new Event("change", { bubbles: true }))
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
showPanel({ detail: { index } }) {
|
|
128
|
+
this.element.querySelectorAll("[data-editor-panel]").forEach((panel, place) => panel.toggleAttribute("data-shown", place === index))
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
customColorChanged() {
|
|
132
|
+
if (this.hasCustomRadioTarget) this.customRadioTarget.checked = true
|
|
133
|
+
this.highlightTemplate("custom")
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
highlightTemplate(selected) {
|
|
137
|
+
this.templateLabelTargets.forEach(label => {
|
|
138
|
+
const border = label.querySelector("span")
|
|
139
|
+
if (label.dataset.template === selected) {
|
|
140
|
+
border.classList.remove("border-transparent")
|
|
141
|
+
border.classList.add("border-accent-500")
|
|
142
|
+
} else {
|
|
143
|
+
border.classList.remove("border-accent-500")
|
|
144
|
+
border.classList.add("border-transparent")
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
setPickerValue(wrapper, hex) {
|
|
150
|
+
const input = wrapper.querySelector("input[type='hidden']")
|
|
151
|
+
const swatch = wrapper.querySelector("[data-color-picker-target='swatch']")
|
|
152
|
+
const hexLabel = wrapper.querySelector("[data-color-picker-target='hexLabel']")
|
|
153
|
+
const text = wrapper.querySelector("[data-color-picker-target='text']")
|
|
154
|
+
|
|
155
|
+
if (input) input.value = hex
|
|
156
|
+
if (swatch) swatch.style.backgroundColor = hex
|
|
157
|
+
if (hexLabel) hexLabel.textContent = hex
|
|
158
|
+
if (text) text.value = hex
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
#writeExport() {
|
|
162
|
+
const exported = this.element.querySelector("[data-theme-export]")
|
|
163
|
+
if (!exported) return
|
|
164
|
+
|
|
165
|
+
const roles = Object.keys(this.#roles())
|
|
166
|
+
const block = side => roles.flatMap(role => {
|
|
167
|
+
const field = this.element.querySelector(`[name="theme[${role}][${side}]"]`)
|
|
168
|
+
return field?.value && !ENDS_DECLARATION.test(field.value) ? [` --${role}: ${field.value};\n`] : []
|
|
169
|
+
}).join("")
|
|
170
|
+
const css = `:root {\n${block("light")}}\n\n.dark {\n${block("dark")}}\n`
|
|
171
|
+
exported.value = css
|
|
172
|
+
this.element.querySelector("[data-controller~='clipboard']").dataset.clipboardText = css
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#drawShadow() {
|
|
176
|
+
const settings = SHADOW_SETTINGS.map(setting => this.element.querySelector(`[name="theme[${setting}][light]"]`)?.value)
|
|
177
|
+
const [x, y, blur, spread, colour, opacity] = settings
|
|
178
|
+
const shadow = `${x} ${y} ${blur} ${spread} color-mix(in srgb, ${colour} calc(${opacity} * 100%), transparent)`
|
|
179
|
+
if (settings.every(Boolean) && CSS.supports("box-shadow", shadow)) {
|
|
180
|
+
SHADOWS.forEach(variable => this.#set(variable, shadow))
|
|
181
|
+
} else {
|
|
182
|
+
SHADOWS.forEach(variable => this.#remove(variable))
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
#drawUnsavedFields() {
|
|
187
|
+
this.#unsavedFields().forEach(field => this.apply({ target: field }))
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#unsavedFields() {
|
|
191
|
+
const saved = this.#savedTheme()
|
|
192
|
+
return [...this.element.querySelectorAll("[name^='theme[']")].filter(field => {
|
|
193
|
+
const [, role, side] = field.name.match(THEME_FIELD)
|
|
194
|
+
return field.value !== (saved[role]?.[side] ?? "")
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
#savedTheme() {
|
|
199
|
+
return JSON.parse(this.element.querySelector("[data-saved-theme]")?.dataset.savedTheme ?? "{}")
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
#hasUnsavedChanges() {
|
|
203
|
+
return !this.#leaveAllowed && (this.#unsavedFields().length > 0 || this.#quickChoicesChanged() || this.#pasteTyped())
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
#quickChoicesChanged() {
|
|
207
|
+
return this.#quickChoices().some((choice, place) => choice !== this.#loadedChoices[place])
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
#pasteTyped() {
|
|
211
|
+
return [...this.element.querySelectorAll("[name='pasted_theme']")].some(({ value }) => value.trim() !== "")
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
#quickChoices() {
|
|
215
|
+
return [...this.element.querySelectorAll(QUICK_CHOICES)].map(field => (["radio", "checkbox"].includes(field.type) ? field.checked : field.value))
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
#roles() {
|
|
219
|
+
return JSON.parse(this.element.querySelector("[data-theme-roles]").dataset.themeRoles)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
#set(variable, value) {
|
|
223
|
+
this.#rootStyle().setProperty(variable, value)
|
|
224
|
+
this.#setVariables.add(variable)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
#remove(variable) {
|
|
228
|
+
this.#rootStyle().removeProperty(variable)
|
|
229
|
+
this.#setVariables.delete(variable)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
#rootStyle() {
|
|
233
|
+
return this.element.ownerDocument.documentElement.style
|
|
234
|
+
}
|
|
235
|
+
}
|
|
@@ -56,6 +56,31 @@ module KeystoneUi
|
|
|
56
56
|
"shadow-offset-y" => { kind: :signed_length, variables: [] }
|
|
57
57
|
}.freeze
|
|
58
58
|
|
|
59
|
+
GROUPS = {
|
|
60
|
+
"Colors" => {
|
|
61
|
+
"Page" => %w[background foreground],
|
|
62
|
+
"Primary" => %w[primary primary-foreground],
|
|
63
|
+
"Secondary" => %w[secondary secondary-foreground],
|
|
64
|
+
"Accent" => %w[accent accent-foreground],
|
|
65
|
+
"Muted" => %w[muted muted-foreground],
|
|
66
|
+
"Card" => %w[card card-foreground],
|
|
67
|
+
"Popover" => %w[popover popover-foreground],
|
|
68
|
+
"Destructive" => %w[destructive destructive-foreground],
|
|
69
|
+
"Border, input and ring" => %w[border input ring],
|
|
70
|
+
"Chart" => %w[chart-1 chart-2 chart-3 chart-4 chart-5],
|
|
71
|
+
"Sidebar" => %w[sidebar sidebar-foreground sidebar-primary sidebar-primary-foreground sidebar-accent sidebar-accent-foreground sidebar-border sidebar-ring]
|
|
72
|
+
},
|
|
73
|
+
"Typography" => {
|
|
74
|
+
"Fonts" => %w[font-sans font-serif font-mono font-heading],
|
|
75
|
+
"Font weights" => %w[font-weight-normal font-weight-medium font-weight-strong font-weight-heading],
|
|
76
|
+
"Letter spacing" => %w[letter-spacing]
|
|
77
|
+
},
|
|
78
|
+
"Other" => {
|
|
79
|
+
"Shape" => %w[radius spacing border-width],
|
|
80
|
+
"Shadow" => %w[shadow-color shadow-opacity shadow-blur shadow-spread shadow-offset-x shadow-offset-y]
|
|
81
|
+
}
|
|
82
|
+
}.freeze
|
|
83
|
+
|
|
59
84
|
def self.names
|
|
60
85
|
ROLES.keys
|
|
61
86
|
end
|
|
@@ -5,16 +5,18 @@
|
|
|
5
5
|
offers_colours = KeystoneUi::Preferences.configuration.account_colors
|
|
6
6
|
offers_look = KeystoneUi::Preferences.configuration.account_looks && KeystoneUi.configuration.looks.any?
|
|
7
7
|
drawn = KeystoneUi::Preferences::AppearanceChoice.new(person: account, account: nil).colours
|
|
8
|
+
sent = request.get? ? {} : local_assigns[:selection].to_h
|
|
8
9
|
%>
|
|
9
10
|
|
|
10
11
|
<% if !offers_colours && !offers_look %>
|
|
11
12
|
<%= ui_alert(message: "This app does not let accounts choose their colours or look.") %>
|
|
12
13
|
<% else %>
|
|
14
|
+
<% editor = capture do %>
|
|
13
15
|
<%= ui_panel(padding: :lg) do %>
|
|
14
|
-
<%= form_with(url: submit_url, method: :patch, data: { turbo: false
|
|
16
|
+
<%= form_with(url: submit_url, method: :patch, data: { turbo: false }) do %>
|
|
15
17
|
<div style="display: flex; flex-direction: column; gap: 2rem;">
|
|
16
18
|
<% if offers_colours %>
|
|
17
|
-
<%= render partial: "keystone_ui/preferences/settings/colour_choices", locals: { saved: saved, drawn: drawn, pastes: true, presets: true, own_theme_hint: "The account's current choice is its own theme." } %>
|
|
19
|
+
<%= render partial: "keystone_ui/preferences/settings/colour_choices", locals: { saved: saved, drawn: drawn, pastes: true, presets: true, own_theme_hint: "The account's current choice is its own theme.", id_prefix: "account-appearance", sent_paste: sent[:pasted_theme] } %>
|
|
18
20
|
<% end %>
|
|
19
21
|
|
|
20
22
|
<% if offers_look %>
|
|
@@ -32,10 +34,20 @@
|
|
|
32
34
|
<% end %>
|
|
33
35
|
<% end %>
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
<% if offers_colours %>
|
|
38
|
+
<%= render partial: "keystone_ui/preferences/settings/theme_settings", locals: { saved: saved, id_prefix: "account-appearance", sent_theme: sent[:theme], sent_paste: sent[:pasted_theme] } %>
|
|
39
|
+
<% end %>
|
|
40
|
+
|
|
41
|
+
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem;">
|
|
36
42
|
<%= ui_button(label: "Save", type: :submit) %>
|
|
43
|
+
<% if offers_colours %>
|
|
44
|
+
<%= ui_button(label: "Reset", variant: :secondary, type: :button, data: { action: "keystone-ui--preferences--appearance-editor#reset" }) %>
|
|
45
|
+
<% end %>
|
|
37
46
|
</div>
|
|
38
47
|
</div>
|
|
39
48
|
<% end %>
|
|
40
49
|
<% end %>
|
|
41
50
|
<% end %>
|
|
51
|
+
|
|
52
|
+
<%= render partial: "keystone_ui/preferences/settings/editor_layout", locals: { editor: editor, previews: offers_colours } %>
|
|
53
|
+
<% end %>
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
appearance = KeystoneUi::Preferences::AppearanceChoice.new(person: person, account: account)
|
|
6
6
|
drawn = appearance.colours
|
|
7
7
|
saved = KeystoneUi::Preferences::ComponentPreference.find_by(owner: person, component_key: "colours")&.value || { "template_name" => "default" }
|
|
8
|
+
sent = request.get? ? {} : local_assigns[:selection].to_h
|
|
8
9
|
saved_look = KeystoneUi::Preferences::ComponentPreference.find_by(owner: person, component_key: "look")&.value.to_h["look"]
|
|
9
10
|
%>
|
|
10
11
|
|
|
@@ -12,29 +13,40 @@
|
|
|
12
13
|
<%= ui_alert(message: "Your account sets the colours for everyone.") %>
|
|
13
14
|
<% end %>
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
<%=
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
<% editor = capture do %>
|
|
17
|
+
<%= ui_panel(padding: :lg) do %>
|
|
18
|
+
<%= form_with(url: submit_url, method: :patch, data: { turbo: false }) do %>
|
|
19
|
+
<div style="display: flex; flex-direction: column; gap: 2rem;">
|
|
20
|
+
<% if chooses_colours %>
|
|
21
|
+
<%= render partial: "keystone_ui/preferences/settings/colour_choices", locals: { saved: saved, drawn: drawn, pastes: true, presets: true, sent_paste: sent[:pasted_theme] } %>
|
|
22
|
+
<% end %>
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
<% if appearance.person_chooses_look? && KeystoneUi.configuration.looks.any? %>
|
|
25
|
+
<%= render partial: "keystone_ui/preferences/settings/look_choices", locals: { saved_look: saved_look } %>
|
|
26
|
+
<% end %>
|
|
27
|
+
|
|
28
|
+
<%= ui_section(title: "Mode", spacing: :sm) do %>
|
|
29
|
+
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem;">
|
|
30
|
+
<% KeystoneUi::ThemeChoice::MODES.each do |mode| %>
|
|
31
|
+
<% next if mode == "custom" && !(chooses_colours || appearance.custom_offered?) %>
|
|
32
|
+
<%= ui_radio_card(name: "mode", value: mode, label: mode.capitalize, checked: appearance.mode == mode) %>
|
|
33
|
+
<% end %>
|
|
34
|
+
</div>
|
|
35
|
+
<% end %>
|
|
36
|
+
|
|
37
|
+
<% if chooses_colours %>
|
|
38
|
+
<%= render partial: "keystone_ui/preferences/settings/theme_settings", locals: { saved: saved, sent_theme: sent[:theme], sent_paste: sent[:pasted_theme] } %>
|
|
39
|
+
<% end %>
|
|
25
40
|
|
|
26
|
-
<%= ui_section(title: "Mode", spacing: :sm) do %>
|
|
27
41
|
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem;">
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<%=
|
|
42
|
+
<%= ui_button(label: "Save", type: :submit) %>
|
|
43
|
+
<% if chooses_colours %>
|
|
44
|
+
<%= ui_button(label: "Reset", variant: :secondary, type: :button, data: { action: "keystone-ui--preferences--appearance-editor#reset" }) %>
|
|
31
45
|
<% end %>
|
|
32
46
|
</div>
|
|
33
|
-
<% end %>
|
|
34
|
-
|
|
35
|
-
<div>
|
|
36
|
-
<%= ui_button(label: "Save", type: :submit) %>
|
|
37
47
|
</div>
|
|
38
|
-
|
|
48
|
+
<% end %>
|
|
39
49
|
<% end %>
|
|
40
50
|
<% end %>
|
|
51
|
+
|
|
52
|
+
<%= render partial: "keystone_ui/preferences/settings/editor_layout", locals: { editor: editor, previews: chooses_colours } %>
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
palette_hex = ->(colour, palette) { colour.to_s.start_with?("#") ? colour.to_s : palette.call(colour)[500] }
|
|
4
4
|
templates = { "default" => { accent: configuration.default_accent, surface: configuration.default_surface, text: configuration.default_text, label: "Default" } }
|
|
5
5
|
KeystoneUi::Looks::Templates.all.each { |name, template| templates[name.to_s] = template }
|
|
6
|
-
saved_preset = KeystoneUi::Looks::Themes.all.find { |name, _preset| name.to_s == saved["preset_name"] }&.last
|
|
7
6
|
%>
|
|
8
7
|
|
|
9
8
|
<%= ui_section(title: "Theme", spacing: :sm) do %>
|
|
@@ -16,13 +15,13 @@
|
|
|
16
15
|
value: name,
|
|
17
16
|
selected: saved["template_name"] == name,
|
|
18
17
|
input_data: {
|
|
19
|
-
action: "keystone-ui--preferences--
|
|
18
|
+
action: "keystone-ui--preferences--appearance-editor#selectTemplate",
|
|
20
19
|
"accent-hex": accent_hex,
|
|
21
20
|
"surface-hex": surface_hex,
|
|
22
21
|
"text-hex": template[:text]
|
|
23
22
|
},
|
|
24
23
|
label_data: {
|
|
25
|
-
"keystone-ui--preferences--
|
|
24
|
+
"keystone-ui--preferences--appearance-editor-target": "templateLabel",
|
|
26
25
|
template: name
|
|
27
26
|
}
|
|
28
27
|
) do %>
|
|
@@ -38,11 +37,11 @@
|
|
|
38
37
|
value: name.to_s,
|
|
39
38
|
selected: saved["preset_name"] == name.to_s,
|
|
40
39
|
input_data: {
|
|
41
|
-
action: "keystone-ui--preferences--
|
|
40
|
+
action: "keystone-ui--preferences--appearance-editor#selectPreset",
|
|
42
41
|
theme: preset[:theme].to_json
|
|
43
42
|
},
|
|
44
43
|
label_data: {
|
|
45
|
-
"keystone-ui--preferences--
|
|
44
|
+
"keystone-ui--preferences--appearance-editor-target": "templateLabel",
|
|
46
45
|
template: name.to_s
|
|
47
46
|
}
|
|
48
47
|
) do %>
|
|
@@ -57,10 +56,10 @@
|
|
|
57
56
|
value: "",
|
|
58
57
|
selected: saved["template_name"].blank? && !saved.key?("theme") && !saved.key?("preset_name"),
|
|
59
58
|
input_data: {
|
|
60
|
-
"keystone-ui--preferences--
|
|
59
|
+
"keystone-ui--preferences--appearance-editor-target": "customRadio"
|
|
61
60
|
},
|
|
62
61
|
label_data: {
|
|
63
|
-
"keystone-ui--preferences--
|
|
62
|
+
"keystone-ui--preferences--appearance-editor-target": "templateLabel",
|
|
64
63
|
template: "custom"
|
|
65
64
|
}
|
|
66
65
|
) do %>
|
|
@@ -71,25 +70,29 @@
|
|
|
71
70
|
<p class="ks-hint"><%= local_assigns.fetch(:own_theme_hint, "Your current choice is your own theme.") %></p>
|
|
72
71
|
<% end %>
|
|
73
72
|
<% if local_assigns[:pastes] %>
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
<% id_prefix = local_assigns.fetch(:id_prefix, "appearance") %>
|
|
74
|
+
<div class="<%= Keystone::Ui::FormFieldComponent::WRAPPER_CLASSES %>">
|
|
75
|
+
<%= label_tag "#{id_prefix}-pasted-theme", "Paste a theme", class: Keystone::Ui::FormFieldComponent::LABEL_CLASSES %>
|
|
76
|
+
<%= text_area_tag "pasted_theme", local_assigns[:sent_paste], id: "#{id_prefix}-pasted-theme", rows: 3, class: Keystone::Ui::TextareaComponent::BASE_CLASSES %>
|
|
77
|
+
<p class="<%= Keystone::Ui::FormFieldComponent::HINT_CLASSES %>">A :root block and a .dark block in shadcn/ui's variable names, as tweakcn and shadcn's theme pages export them.</p>
|
|
78
|
+
</div>
|
|
76
79
|
<% end %>
|
|
77
80
|
<% end %>
|
|
78
81
|
|
|
79
82
|
<%= ui_section(title: "Accent Color", spacing: :sm) do %>
|
|
80
|
-
<div data-keystone-ui--preferences--
|
|
83
|
+
<div data-keystone-ui--preferences--appearance-editor-target="accentPicker">
|
|
81
84
|
<%= ui_color_picker(name: "accent", value: palette_hex.call(drawn[:accent], KeystoneUi::Looks::Palettes.method(:accent))) %>
|
|
82
85
|
</div>
|
|
83
86
|
<% end %>
|
|
84
87
|
|
|
85
88
|
<%= ui_section(title: "Surface", spacing: :sm) do %>
|
|
86
|
-
<div data-keystone-ui--preferences--
|
|
89
|
+
<div data-keystone-ui--preferences--appearance-editor-target="surfacePicker">
|
|
87
90
|
<%= ui_color_picker(name: "surface", value: palette_hex.call(drawn[:surface], KeystoneUi::Looks::Palettes.method(:surface))) %>
|
|
88
91
|
</div>
|
|
89
92
|
<% end %>
|
|
90
93
|
|
|
91
94
|
<%= ui_section(title: "Text Color", spacing: :sm) do %>
|
|
92
|
-
<div data-keystone-ui--preferences--
|
|
95
|
+
<div data-keystone-ui--preferences--appearance-editor-target="textPicker">
|
|
93
96
|
<%= ui_color_picker(name: "text", value: drawn[:text]) %>
|
|
94
97
|
</div>
|
|
95
98
|
<% end %>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<div data-appearance-editor data-controller="keystone-ui--preferences--appearance-editor" data-action="tab-switcher:change->keystone-ui--preferences--appearance-editor#showPanel submit->keystone-ui--preferences--appearance-editor#save turbo:before-visit@document->keystone-ui--preferences--appearance-editor#confirmLeave beforeunload@window->keystone-ui--preferences--appearance-editor#warnBeforeUnload">
|
|
2
|
+
<% if previews %>
|
|
3
|
+
<style>
|
|
4
|
+
[data-editor-panel]:not([data-shown]) { display: none; }
|
|
5
|
+
@media (min-width: 64rem) {
|
|
6
|
+
[data-appearance-editor] .ks-tab-bar { display: none; }
|
|
7
|
+
[data-editor-panels] { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.5rem; align-items: start; }
|
|
8
|
+
[data-editor-panel]:not([data-shown]) { display: block; }
|
|
9
|
+
}
|
|
10
|
+
</style>
|
|
11
|
+
<%= ui_tab_switcher(tabs: %w[Edit Preview]) do %>
|
|
12
|
+
<div data-editor-panels>
|
|
13
|
+
<div data-editor-panel data-shown><%= editor %></div>
|
|
14
|
+
<div data-editor-panel><%= render partial: "keystone_ui/preferences/settings/theme_preview" %></div>
|
|
15
|
+
</div>
|
|
16
|
+
<% end %>
|
|
17
|
+
<% else %>
|
|
18
|
+
<%= editor %>
|
|
19
|
+
<% end %>
|
|
20
|
+
<div data-leave-question>
|
|
21
|
+
<%= ui_modal(title: "Leave without saving?", size: :sm) do %>
|
|
22
|
+
<p>Your changes are not saved yet.</p>
|
|
23
|
+
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem;">
|
|
24
|
+
<%= ui_button(label: "Leave without saving", variant: :danger, type: :button, data: { action: "keystone-ui--preferences--appearance-editor#leave" }) %>
|
|
25
|
+
<%= ui_button(label: "Stay", variant: :secondary, type: :button, data: { action: "modal#close" }) %>
|
|
26
|
+
</div>
|
|
27
|
+
<% end %>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<div data-theme-preview style="display: flex; flex-direction: column; gap: 1.5rem;">
|
|
2
|
+
<% %w[light dark].each do |side| %>
|
|
3
|
+
<div data-theme="<%= side %>">
|
|
4
|
+
<%= ui_panel do %>
|
|
5
|
+
<div style="display: flex; flex-direction: column; gap: 1.5rem;">
|
|
6
|
+
<%= ui_card(title: "Quarterly review", summary: "Revenue grew in every region this quarter.", link: "#", cta: "Open") %>
|
|
7
|
+
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem;">
|
|
8
|
+
<%= ui_button(label: "Save", type: :button) %>
|
|
9
|
+
<%= ui_button(label: "Cancel", variant: :secondary, type: :button) %>
|
|
10
|
+
<%= ui_button(label: "Delete", variant: :danger, type: :button) %>
|
|
11
|
+
</div>
|
|
12
|
+
<div style="display: flex; flex-direction: column; gap: 1rem;">
|
|
13
|
+
<%= ui_form_field(attribute: "preview_name", label: "Name", value: "Northwind Traders") %>
|
|
14
|
+
<%= ui_form_field(attribute: "preview_region", label: "Region", type: :select, options: [ [ "North", "north" ], [ "South", "south" ] ], value: "north", required: true) %>
|
|
15
|
+
</div>
|
|
16
|
+
<%= ui_data_table(
|
|
17
|
+
items: [ { customer: "Northwind Traders", region: "North", total: "$12,400" }, { customer: "Harbor Supply", region: "South", total: "$8,950" }, { customer: "Fern & Co", region: "North", total: "$4,120" } ],
|
|
18
|
+
columns: [ { customer: "Customer" }, { region: "Region" }, { total: "Total" } ]
|
|
19
|
+
) %>
|
|
20
|
+
<%= ui_line_chart(
|
|
21
|
+
labels: %w[Jan Feb Mar Apr May Jun],
|
|
22
|
+
series: [ { name: "This year", data: [ 12, 19, 15, 24, 22, 30 ] }, { name: "Last year", data: [ 10, 14, 13, 17, 19, 21 ] } ],
|
|
23
|
+
height: :sm
|
|
24
|
+
) %>
|
|
25
|
+
<nav class="ks-sidebar" aria-label="Sample navigation">
|
|
26
|
+
<% [ "Dashboard", "Customers", "Reports" ].each_with_index do |label, index| %>
|
|
27
|
+
<a href="#" class="<%= [ Keystone::Ui::NavigationComponent::SIDEBAR_TAB_CLASSES, (Keystone::Ui::NavigationComponent::ACTIVE_CLASS if index.zero?) ].compact.join(" ") %>"><%= label %></a>
|
|
28
|
+
<% end %>
|
|
29
|
+
</nav>
|
|
30
|
+
</div>
|
|
31
|
+
<% end %>
|
|
32
|
+
</div>
|
|
33
|
+
<% end %>
|
|
34
|
+
</div>
|
|
@@ -1,17 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
<% saved_preset = KeystoneUi::Looks::Themes.all.find { |name, _preset| name.to_s == saved["preset_name"] }&.last %>
|
|
2
|
+
<% theme = saved_preset ? saved_preset[:theme] : saved["theme"].to_h %>
|
|
3
|
+
<% shown = local_assigns[:sent_theme] || theme %>
|
|
4
|
+
<% check = KeystoneUi::Preferences::CheckedTheme.new(local_assigns[:sent_paste].present? ? {} : local_assigns[:sent_theme].to_h) %>
|
|
5
|
+
<% id_prefix = local_assigns.fetch(:id_prefix, "appearance") %>
|
|
6
|
+
<% fonts_id = "#{id_prefix}-theme-fonts" %>
|
|
7
|
+
<% roles = KeystoneUi::Preferences::ThemeRoles::ROLES.to_h { |name, role| [ name, role.merge(hover: KeystoneUi::Preferences::ThemeCss::HOVERS[name]).compact ] } %>
|
|
8
|
+
<div data-action="change->keystone-ui--preferences--appearance-editor#apply input->keystone-ui--preferences--appearance-editor#apply" data-theme-roles="<%= roles.to_json %>" data-saved-theme="<%= theme.to_json %>" style="display: flex; flex-direction: column; gap: 2rem;">
|
|
9
|
+
<% KeystoneUi::Preferences::ThemeRoles::GROUPS.each do |group, sets| %>
|
|
10
|
+
<%= ui_section(title: group, spacing: :sm) do %>
|
|
11
|
+
<% sets.each do |set, names| %>
|
|
12
|
+
<fieldset style="border: 0; padding: 0; margin: 0; min-width: 0;">
|
|
13
|
+
<legend class="<%= Keystone::Ui::FormFieldComponent::LABEL_CLASSES %>"><%= set %></legend>
|
|
14
|
+
<div style="display: flex; flex-wrap: wrap; gap: 1rem;">
|
|
15
|
+
<% names.each do |name| %>
|
|
16
|
+
<% role = KeystoneUi::Preferences::ThemeRoles::ROLES.fetch(name) %>
|
|
17
|
+
<% if role[:kind] == :colour %><div role="group" aria-label="--<%= name %>" style="display: flex; flex-wrap: wrap; gap: 1rem;"><% end %>
|
|
18
|
+
<% (role[:kind] == :colour ? %w[light dark] : %w[light]).each do |side| %>
|
|
19
|
+
<% field_name = "theme[#{name}][#{side}]" %>
|
|
20
|
+
<% value = shown.dig(name, side).to_s %>
|
|
21
|
+
<% label = role[:kind] == :colour ? "--#{name}, #{side}" : "--#{name}" %>
|
|
22
|
+
<% if %i[colour shadow_colour].include?(role[:kind]) && (value.empty? || value.match?(KeystoneUi::Preferences::CheckedTheme::COLOUR)) %>
|
|
23
|
+
<%= ui_color_picker(name: field_name, value: value, label: label) %>
|
|
24
|
+
<% else %>
|
|
25
|
+
<% field_id = "#{id_prefix}-#{field_name.parameterize}" %>
|
|
26
|
+
<div class="<%= Keystone::Ui::FormFieldComponent::WRAPPER_CLASSES %>">
|
|
27
|
+
<%= label_tag field_id, label, class: Keystone::Ui::FormFieldComponent::LABEL_CLASSES %>
|
|
28
|
+
<%= text_field_tag field_name, value, id: field_id, class: Keystone::Ui::InputComponent::BASE_CLASSES, list: (fonts_id if role[:kind] == :font_list) %>
|
|
29
|
+
</div>
|
|
30
|
+
<% end %>
|
|
31
|
+
<% end %>
|
|
32
|
+
<% if name == check.failing_setting %>
|
|
33
|
+
<p class="<%= Keystone::Ui::FormFieldComponent::ERROR_CLASSES %>"><%= check.refusal.message %></p>
|
|
34
|
+
<% end %>
|
|
35
|
+
<% if role[:kind] == :colour %></div><% end %>
|
|
36
|
+
<% end %>
|
|
37
|
+
</div>
|
|
38
|
+
</fieldset>
|
|
14
39
|
<% end %>
|
|
15
40
|
<% end %>
|
|
41
|
+
<% end %>
|
|
42
|
+
<div class="<%= Keystone::Ui::FormFieldComponent::WRAPPER_CLASSES %>">
|
|
43
|
+
<%= label_tag "#{id_prefix}-theme-export", "Export", class: Keystone::Ui::FormFieldComponent::LABEL_CLASSES %>
|
|
44
|
+
<%= content_tag :textarea, nil, id: "#{id_prefix}-theme-export", readonly: true, rows: 8, class: Keystone::Ui::TextareaComponent::BASE_CLASSES, data: { theme_export: "" } %>
|
|
45
|
+
<div><%= ui_copy_button(text: "", error_message: "Select the text to copy it") %></div>
|
|
16
46
|
</div>
|
|
17
|
-
|
|
47
|
+
<datalist id="<%= fonts_id %>">
|
|
48
|
+
<% (KeystoneUi::Preferences.configuration.theme_fonts + KeystoneUi::Preferences::CheckedTheme::SYSTEM_FONTS).each do |font| %>
|
|
49
|
+
<option value="<%= font %>"></option>
|
|
50
|
+
<% end %>
|
|
51
|
+
</datalist>
|
|
52
|
+
</div>
|
|
@@ -11,7 +11,7 @@ module KeystoneUi
|
|
|
11
11
|
|
|
12
12
|
source_root File.expand_path("templates", __dir__)
|
|
13
13
|
|
|
14
|
-
desc "Installs KeystoneUi::Preferences: copies its migration and its
|
|
14
|
+
desc "Installs KeystoneUi::Preferences: copies its migration and its appearance editor script."
|
|
15
15
|
|
|
16
16
|
def copy_migration
|
|
17
17
|
migration_template(
|
|
@@ -20,9 +20,9 @@ module KeystoneUi
|
|
|
20
20
|
)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
def
|
|
24
|
-
script = File.expand_path("../../../../../app/javascript/keystone_ui/preferences/
|
|
25
|
-
create_file "app/javascript/controllers/keystone_ui/preferences/
|
|
23
|
+
def copy_appearance_editor_script
|
|
24
|
+
script = File.expand_path("../../../../../app/javascript/keystone_ui/preferences/appearance_editor_controller.js", __dir__)
|
|
25
|
+
create_file "app/javascript/controllers/keystone_ui/preferences/appearance_editor_controller.js", File.read(script)
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
@@ -11,7 +11,7 @@ module KeystoneUi
|
|
|
11
11
|
|
|
12
12
|
source_root File.expand_path("templates", __dir__)
|
|
13
13
|
|
|
14
|
-
desc "Updates KeystoneUi::Preferences: copies migrations added since it was installed and the
|
|
14
|
+
desc "Updates KeystoneUi::Preferences: copies migrations added since it was installed and the appearance editor script when the app has none."
|
|
15
15
|
|
|
16
16
|
def copy_remove_extra_owner_index_migration
|
|
17
17
|
migration_template(
|
|
@@ -27,11 +27,11 @@ module KeystoneUi
|
|
|
27
27
|
)
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
-
def
|
|
31
|
-
copy = "app/javascript/controllers/keystone_ui/preferences/
|
|
30
|
+
def copy_appearance_editor_script
|
|
31
|
+
copy = "app/javascript/controllers/keystone_ui/preferences/appearance_editor_controller.js"
|
|
32
32
|
return if File.exist?(File.join(destination_root, copy))
|
|
33
33
|
|
|
34
|
-
create_file copy, File.read(File.expand_path("../../../../../app/javascript/keystone_ui/preferences/
|
|
34
|
+
create_file copy, File.read(File.expand_path("../../../../../app/javascript/keystone_ui/preferences/appearance_editor_controller.js", __dir__))
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: keystone_ui-preferences
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tyler Schneider
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.
|
|
18
|
+
version: 0.47.0
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.
|
|
25
|
+
version: 0.47.0
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: keystone_ui-looks
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -43,14 +43,14 @@ dependencies:
|
|
|
43
43
|
requirements:
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 0.
|
|
46
|
+
version: 0.23.0
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: 0.
|
|
53
|
+
version: 0.23.0
|
|
54
54
|
- !ruby/object:Gem::Dependency
|
|
55
55
|
name: railties
|
|
56
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -107,7 +107,7 @@ files:
|
|
|
107
107
|
- app/controllers/concerns/keystone_ui/preferences/component_preferences.rb
|
|
108
108
|
- app/controllers/keystone_ui/preferences/application_controller.rb
|
|
109
109
|
- app/controllers/keystone_ui/preferences/component_preferences_controller.rb
|
|
110
|
-
- app/javascript/keystone_ui/preferences/
|
|
110
|
+
- app/javascript/keystone_ui/preferences/appearance_editor_controller.js
|
|
111
111
|
- app/models/keystone_ui/preferences/appearance_choice.rb
|
|
112
112
|
- app/models/keystone_ui/preferences/application_record.rb
|
|
113
113
|
- app/models/keystone_ui/preferences/checked_theme.rb
|
|
@@ -130,9 +130,11 @@ files:
|
|
|
130
130
|
- app/views/keystone_ui/preferences/settings/_account_layouts.html.erb
|
|
131
131
|
- app/views/keystone_ui/preferences/settings/_appearance.html.erb
|
|
132
132
|
- app/views/keystone_ui/preferences/settings/_colour_choices.html.erb
|
|
133
|
+
- app/views/keystone_ui/preferences/settings/_editor_layout.html.erb
|
|
133
134
|
- app/views/keystone_ui/preferences/settings/_look_choices.html.erb
|
|
134
135
|
- app/views/keystone_ui/preferences/settings/_navigation_order.html.erb
|
|
135
136
|
- app/views/keystone_ui/preferences/settings/_navigation_placement.html.erb
|
|
137
|
+
- app/views/keystone_ui/preferences/settings/_theme_preview.html.erb
|
|
136
138
|
- app/views/keystone_ui/preferences/settings/_theme_settings.html.erb
|
|
137
139
|
- config/routes.rb
|
|
138
140
|
- lib/generators/keystone_ui/preferences/install/install_generator.rb
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { Controller } from "@hotwired/stimulus"
|
|
2
|
-
|
|
3
|
-
export default class extends Controller {
|
|
4
|
-
static targets = ["accentPicker", "surfacePicker", "textPicker", "customRadio", "templateLabel"]
|
|
5
|
-
|
|
6
|
-
connect() {
|
|
7
|
-
this.colorPickerTargets().forEach(picker => picker.addEventListener("change", () => this.customColorChanged()))
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
colorPickerTargets() {
|
|
11
|
-
return [
|
|
12
|
-
this.hasAccentPickerTarget && this.accentPickerTarget,
|
|
13
|
-
this.hasSurfacePickerTarget && this.surfacePickerTarget,
|
|
14
|
-
this.hasTextPickerTarget && this.textPickerTarget
|
|
15
|
-
].filter(Boolean)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
selectTemplate(event) {
|
|
19
|
-
const input = event.currentTarget
|
|
20
|
-
const label = input.closest("[data-template]")
|
|
21
|
-
const accentHex = input.dataset.accentHex
|
|
22
|
-
const surfaceHex = input.dataset.surfaceHex
|
|
23
|
-
const textHex = input.dataset.textHex
|
|
24
|
-
|
|
25
|
-
this.setPickerValue(this.accentPickerTarget, accentHex)
|
|
26
|
-
this.setPickerValue(this.surfacePickerTarget, surfaceHex)
|
|
27
|
-
this.setPickerValue(this.textPickerTarget, textHex)
|
|
28
|
-
|
|
29
|
-
this.highlightTemplate(label.dataset.template)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
selectPreset(event) {
|
|
33
|
-
const input = event.currentTarget
|
|
34
|
-
const theme = JSON.parse(input.dataset.theme)
|
|
35
|
-
|
|
36
|
-
Object.entries(theme).forEach(([role, sides]) => {
|
|
37
|
-
Object.entries(sides).forEach(([side, value]) => this.setThemeField(`theme[${role}][${side}]`, value))
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
this.highlightTemplate(input.closest("[data-template]").dataset.template)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
setThemeField(name, value) {
|
|
44
|
-
const field = this.element.querySelector(`[name="${name}"]`)
|
|
45
|
-
if (!field) return
|
|
46
|
-
|
|
47
|
-
const picker = field.closest("[data-controller~='color-picker']")
|
|
48
|
-
if (picker) {
|
|
49
|
-
this.setPickerValue(picker, value)
|
|
50
|
-
} else {
|
|
51
|
-
field.value = value
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
customColorChanged() {
|
|
56
|
-
if (this.hasCustomRadioTarget) this.customRadioTarget.checked = true
|
|
57
|
-
this.highlightTemplate("custom")
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
highlightTemplate(selected) {
|
|
61
|
-
this.templateLabelTargets.forEach(label => {
|
|
62
|
-
const border = label.querySelector("span")
|
|
63
|
-
if (label.dataset.template === selected) {
|
|
64
|
-
border.classList.remove("border-transparent")
|
|
65
|
-
border.classList.add("border-accent-500")
|
|
66
|
-
} else {
|
|
67
|
-
border.classList.remove("border-accent-500")
|
|
68
|
-
border.classList.add("border-transparent")
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
setPickerValue(wrapper, hex) {
|
|
74
|
-
const input = wrapper.querySelector("input[type='hidden']")
|
|
75
|
-
const swatch = wrapper.querySelector("[data-color-picker-target='swatch']")
|
|
76
|
-
const hexLabel = wrapper.querySelector("[data-color-picker-target='hexLabel']")
|
|
77
|
-
const text = wrapper.querySelector("[data-color-picker-target='text']")
|
|
78
|
-
|
|
79
|
-
if (input) input.value = hex
|
|
80
|
-
if (swatch) swatch.style.backgroundColor = hex
|
|
81
|
-
if (hexLabel) hexLabel.textContent = hex
|
|
82
|
-
if (text) text.value = hex
|
|
83
|
-
}
|
|
84
|
-
}
|