Skip to content

Commit d8ea591

Browse files
Colors (#3)
1 parent e727bc3 commit d8ea591

45 files changed

Lines changed: 731 additions & 297 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
ruby-version: ["3.2", "3.3"]
17+
18+
env:
19+
RAILS_ENV: test
20+
SECRET_KEY_BASE_DUMMY: 1
21+
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Set up Ruby ${{ matrix.ruby-version }}
26+
uses: ruby/setup-ruby@v1
27+
with:
28+
ruby-version: ${{ matrix.ruby-version }}
29+
bundler-cache: true
30+
31+
- name: Set up database
32+
run: cd test/dummy && bin/rails db:setup
33+
34+
- name: Run tests
35+
run: bundle exec rake test

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Guidance for AI agents working in this repository.
2222

2323
## Conventions
2424

25+
- Use "layered-ui-rails" not "Layered UI" when referring to the project
26+
- Use normal dashes '-' not long ones '—'
2527
- Locale: Favour en-GB (British English), unless terms are defined by technical standards (e.g. LICENSE, COLOR).
2628
- Titles: capitalise first word only (e.g. "This title")
2729
- Document new styles in the dummy app

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ RUN apt-get update -qq && \
2525
apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config && \
2626
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2727

28-
# Install all gem groups development deps (puma, devise, tailwindcss-rails…)
28+
# Install all gem groups - development deps (puma, devise, tailwindcss-rails…)
2929
# are runtime requirements for the dummy app.
3030
COPY Gemfile Gemfile.lock layered-ui-rails.gemspec ./
3131
COPY lib/layered/ui/version.rb lib/layered/ui/version.rb

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# layered-ui-rails
22

3-
An open source, Rails 8+ engine that provides WCAG 2.2 AA compliant design tokens, Tailwind CSS utilities, and Stimulus controllers for theme switching, mobile navigation, slide-out panels, modals, and tabs. Ships as pure frontend with no server-side dependencies beyond Rails and Tailwind CSS.
3+
[![CI](https://github.com/layered-ai-public/layered-ui-rails/actions/workflows/ci.yml/badge.svg)](https://github.com/layered-ai-public/layered-ui-rails/actions/workflows/ci.yml)
4+
[![WCAG 2.2 AA](https://img.shields.io/badge/WCAG_2.2-AA-green)](https://www.w3.org/WAI/WCAG22/quickref/)
5+
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6+
7+
An open source, Rails 8+ engine that provides WCAG 2.2 AA compliant design tokens, Tailwind CSS utilities, and Stimulus controllers for theme switching, mobile navigation, slide-out panels, modals, and tabs. Ships as pure frontend with no server-side dependencies beyond Rails and Tailwind CSS. See the [live demo](https://layered-ui-rails.layered.ai).
48

59
<table align="center">
610
<tr>
@@ -38,10 +42,6 @@ The install generator will:
3842
Then update your application layout to render the engine layout:
3943

4044
```erb
41-
<% content_for :l_ui_navigation_items do %>
42-
<%= l_ui_navigation_item "Home", root_path %>
43-
<% end %>
44-
4545
<%= render template: "layouts/layered_ui/application" %>
4646
```
4747

@@ -59,7 +59,7 @@ Then update your application layout to render the engine layout:
5959
- **WCAG 2.2 AA compliant** - skip links, focus indicators, ARIA attributes, and 4.5:1 contrast ratios
6060
- **Components** - buttons, forms, surfaces, tables, tabs, notices, badges, conversations, modals, and pagination
6161
- **Optional integrations** - Devise authentication and Pagy pagination with styled views
62-
- **Customisable branding** - Override the default logos and icons by dropping your own SVGs into `app/assets/images/layered_ui/`
62+
- **Customisable branding** - Override the default logos and icons and colors
6363
- **Google Lighthouse** - `layered-ui-rails` scores a [perfect 100](test/dummy/app/assets/images/lighthouse.webp) across all four Google Lighthouse categories - performance, accessibility, best practices, and SEO
6464

6565
## Documentation

app/assets/tailwind/layered/ui/styles.css

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@
3232

3333
@variant dark (&:where(.dark, .dark *));
3434

35-
/* Colours */
35+
/* Colors */
3636

3737
@layer base {
3838
:root {
39+
--accent: 0 0% 9%;
40+
--accent-foreground: 0 0% 100%;
3941
--background: 0 0% 100%;
4042
--foreground: 0 0% 13%;
4143
--foreground-muted: 0 0% 29%;
4244
--border: 0 0% 91%;
4345
--ring: 0 0% 13%;
4446
--surface: 0 0% 96%;
4547
--surface-active: 0 0% 91%;
46-
--button-primary-bg: 0 0% 9%;
47-
--button-primary-text: 0 0% 100%;
48+
--button-primary-bg: var(--accent);
49+
--button-primary-text: var(--accent-foreground);
4850
--danger: 0 72% 38%;
4951
--danger-light: 0 100% 97%;
5052
--danger-text: 0 72% 35%;
@@ -59,15 +61,17 @@
5961
}
6062

6163
.dark {
64+
--accent: 0 0% 100%;
65+
--accent-foreground: 0 0% 9%;
6266
--background: 0 0% 0%;
6367
--foreground: 0 0% 89%;
6468
--foreground-muted: 0 0% 71%;
6569
--border: 0 0% 16%;
6670
--ring: 0 0% 89%;
6771
--surface: 0 0% 8%;
6872
--surface-active: 0 0% 16%;
69-
--button-primary-bg: 0 0% 100%;
70-
--button-primary-text: 0 0% 9%;
73+
--button-primary-bg: var(--accent);
74+
--button-primary-text: var(--accent-foreground);
7175
--danger: 0 85% 60%;
7276
--danger-light: 0 93% 15%;
7377
--danger-text: 0 85% 64%;
@@ -130,6 +134,8 @@
130134
@theme {
131135
--font-manrope: 'Manrope', ui-sans-serif, system-ui, sans-serif;
132136
--font-inter: 'Inter', ui-sans-serif, system-ui, sans-serif;
137+
--color-accent: hsl(var(--accent));
138+
--color-accent-foreground: hsl(var(--accent-foreground));
133139
--color-background: hsl(var(--background));
134140
--color-foreground: hsl(var(--foreground));
135141
--color-foreground-muted: hsl(var(--foreground-muted));
@@ -438,7 +444,7 @@
438444
.l-ui-navigation__item--active {
439445
@apply navigation__item
440446
font-bold
441-
text-foreground;
447+
text-accent;
442448

443449
&::after {
444450
content: "▸";
@@ -462,7 +468,7 @@
462468
.l-ui-navigation__item--active {
463469
@apply bg-transparent
464470
font-bold
465-
text-foreground;
471+
text-accent;
466472

467473
&::after {
468474
content: "▸";
@@ -806,8 +812,8 @@
806812

807813
.l-ui-tabs__tab--active {
808814
@apply tabs__tab
809-
text-foreground
810-
border-foreground;
815+
text-accent
816+
border-accent;
811817
}
812818

813819
.l-ui-tabs__panel {

lib/generators/layered/ui/copy_assets_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Layered
22
module Ui
33
module Generators
44
class CopyAssetsGenerator < Rails::Generators::Base
5-
desc "Copy layered-ui CSS assets into the host application"
5+
desc "Copy layered-ui-rails CSS assets into the host application"
66

77
def self.source_root
88
Layered::Ui::Engine.root
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
module Layered
2+
module Ui
3+
module Generators
4+
class CreateOverridesGenerator < Rails::Generators::Base
5+
desc "Create a layered-ui-rails color overrides file in the host application"
6+
7+
OVERRIDES_PATH = "app/assets/tailwind/layered_ui_overrides.css"
8+
9+
def create_overrides_file
10+
if File.exist?(OVERRIDES_PATH)
11+
say "Overrides file already exists at #{OVERRIDES_PATH}, skipping", :yellow
12+
return
13+
end
14+
15+
create_file OVERRIDES_PATH, overrides_content
16+
end
17+
18+
private
19+
20+
def overrides_content
21+
<<~CSS
22+
/*
23+
* layered-ui-rails color overrides
24+
*
25+
* Uncomment and edit any variable below to customise the UI.
26+
* This file is NOT overwritten by the install generator, so your
27+
* changes are preserved when you upgrade layered-ui-rails.
28+
*
29+
* Values are HSL channels: <hue> <saturation>% <lightness>%
30+
* Example: --accent: 220 80% 55%;
31+
*/
32+
33+
/* ----------------------------------------------------------------
34+
* Tier 1 - Accent color
35+
*
36+
* Set a single brand color. Primary buttons, active tabs, and
37+
* active navigation items all inherit from these two variables.
38+
* ---------------------------------------------------------------- */
39+
40+
:root {
41+
/* --accent: 0 0% 9%; */
42+
/* --accent-foreground: 0 0% 100%; */
43+
}
44+
45+
.dark {
46+
/* --accent: 0 0% 100%; */
47+
/* --accent-foreground: 0 0% 9%; */
48+
}
49+
50+
/* ----------------------------------------------------------------
51+
* Tier 2 - Full color overrides
52+
*
53+
* Override any individual token. Uncomment only the ones you need.
54+
* ---------------------------------------------------------------- */
55+
56+
/*
57+
:root {
58+
--background: 0 0% 100%;
59+
--foreground: 0 0% 13%;
60+
--foreground-muted: 0 0% 29%;
61+
--border: 0 0% 91%;
62+
--ring: 0 0% 13%;
63+
--surface: 0 0% 96%;
64+
--surface-active: 0 0% 91%;
65+
--button-primary-bg: var(--accent);
66+
--button-primary-text: var(--accent-foreground);
67+
--danger: 0 72% 38%;
68+
--danger-light: 0 100% 97%;
69+
--danger-text: 0 72% 35%;
70+
--success-bg: 142 76% 65%;
71+
--success-text: 142 76% 13%;
72+
--warning-bg: 48 96% 65%;
73+
--warning-text: 48 96% 15%;
74+
--error-bg: 0 84% 75%;
75+
--error-text: 0 93% 12%;
76+
--backdrop: 0 0% 0%;
77+
}
78+
79+
.dark {
80+
--background: 0 0% 0%;
81+
--foreground: 0 0% 89%;
82+
--foreground-muted: 0 0% 71%;
83+
--border: 0 0% 16%;
84+
--ring: 0 0% 89%;
85+
--surface: 0 0% 8%;
86+
--surface-active: 0 0% 16%;
87+
--button-primary-bg: var(--accent);
88+
--button-primary-text: var(--accent-foreground);
89+
--danger: 0 85% 60%;
90+
--danger-light: 0 93% 15%;
91+
--danger-text: 0 85% 64%;
92+
--success-bg: 142 76% 15%;
93+
--success-text: 142 76% 80%;
94+
--warning-bg: 48 96% 15%;
95+
--warning-text: 48 96% 80%;
96+
--error-bg: 0 93% 12%;
97+
--error-text: 0 84% 75%;
98+
--backdrop: 0 0% 0%;
99+
}
100+
*/
101+
CSS
102+
end
103+
end
104+
end
105+
end
106+
end

lib/generators/layered/ui/import_css_generator.rb

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Layered
22
module Ui
33
module Generators
44
class ImportCssGenerator < Rails::Generators::Base
5-
desc "Add layered-ui CSS import to the host application"
5+
desc "Add layered-ui-rails CSS import to the host application"
66

77
def add_css_import
88
application_css = "app/assets/tailwind/application.css"
@@ -11,16 +11,24 @@ def add_css_import
1111

1212
content = File.read(application_css)
1313
import_line = '@import "./layered_ui";'
14+
overrides_line = '@import "./layered_ui_overrides";'
1415

15-
return if content.include?(import_line)
16+
unless content.include?(import_line)
17+
if content.include?('@import "tailwindcss"')
18+
inject_into_file application_css, "\n#{import_line}", after: '@import "tailwindcss";'
19+
say "Added import to #{application_css}", :green
20+
else
21+
append_to_file application_css, "\n#{import_line}\n"
22+
say "Appended import to #{application_css}", :green
23+
end
24+
end
25+
26+
# Re-read in case we just modified it
27+
content = File.read(application_css)
1628

17-
# Insert after the first @import "tailwindcss" line
18-
if content.include?('@import "tailwindcss"')
19-
inject_into_file application_css, "\n#{import_line}", after: '@import "tailwindcss";'
20-
say "Added import to #{application_css}", :green
21-
else
22-
append_to_file application_css, "\n#{import_line}\n"
23-
say "Appended import to #{application_css}", :green
29+
unless content.include?(overrides_line)
30+
inject_into_file application_css, "\n#{overrides_line}", after: import_line
31+
say "Added overrides import to #{application_css}", :green
2432
end
2533
end
2634
end

lib/generators/layered/ui/import_js_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Layered
22
module Ui
33
module Generators
44
class ImportJsGenerator < Rails::Generators::Base
5-
desc "Add layered-ui JavaScript import to the host application"
5+
desc "Add layered-ui-rails JavaScript import to the host application"
66

77
def add_js_import
88
application_js = "app/javascript/application.js"

lib/generators/layered/ui/install_generator.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Layered
22
module Ui
33
module Generators
44
class InstallGenerator < Rails::Generators::Base
5-
desc "Install layered-ui into the host application"
5+
desc "Install layered-ui-rails into the host application"
66

77
def check_dependencies
88
unless Gem.loaded_specs.key?("tailwindcss-rails")
@@ -19,6 +19,10 @@ def copy_assets
1919
invoke "layered:ui:copy_assets"
2020
end
2121

22+
def create_overrides
23+
invoke "layered:ui:create_overrides"
24+
end
25+
2226
def import_css
2327
invoke "layered:ui:import_css"
2428
end

0 commit comments

Comments
 (0)