Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/assets/builds/administrate/application.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/assets/builds/administrate/application.css.map

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions app/assets/stylesheets/administrate/base/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ textarea {
width: 100%;
}

[type="color"] {
padding: 0 0.5em;
}
Comment on lines +95 to +97

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the padding on top and bottom of 0.5em made the color in the input field basically disappear. I had to override it


.color-example {
display: flex;
align-items: center;

span {
width: 1em;
height: 1em;
line-height: 1.5em;
display: inline-block;
margin-right: 0.5em;
}
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this fits in this CSS file to be honest

select {
width: 100%;
}
Expand Down
6 changes: 6 additions & 0 deletions app/views/fields/color/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="field-unit__label">
<%= f.label field.attribute %>
</div>
<div class="field-unit__field">
<%= f.color_field field.attribute %>
</div>
4 changes: 4 additions & 0 deletions app/views/fields/color/_index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="color-example">
<span style="background-color: <%= field.to_s %>"></span>
<%= field.to_s %>
</div>
4 changes: 4 additions & 0 deletions app/views/fields/color/_show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="color-example">
<span style="background-color: <%= field.to_s %>"></span>
<%= field.to_s %>
</div>
1 change: 1 addition & 0 deletions lib/administrate/base_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require "administrate/field/time"
require "administrate/field/url"
require "administrate/field/password"
require "administrate/field/color"

module Administrate
class BaseDashboard
Expand Down
11 changes: 11 additions & 0 deletions lib/administrate/field/color.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require_relative "base"

module Administrate
module Field
class Color < Base
def to_s
data
end
end
end
end
9 changes: 6 additions & 3 deletions spec/example_app/app/dashboards/customer_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class CustomerDashboard < Administrate::BaseDashboard
include_blank: true
),
example_time: Field::Time,
password: Field::Password
password: Field::Password,
favourite_color: Field::Color
}

COLLECTION_ATTRIBUTES = [
Expand All @@ -27,7 +28,8 @@ class CustomerDashboard < Administrate::BaseDashboard
:email_subscriber,
:orders,
:territory,
:example_time
:example_time,
:favourite_color
]

SHOW_PAGE_ATTRIBUTES = ATTRIBUTE_TYPES.keys - [:name]
Expand All @@ -39,7 +41,8 @@ class CustomerDashboard < Administrate::BaseDashboard
:kind,
:territory,
:example_time,
:password
:password,
:favourite_color
].freeze

COLLECTION_FILTERS = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFavouriteColor < ActiveRecord::Migration[8.0]
def change
add_column :customers, :favourite_color, :string
end
end
3 changes: 2 additions & 1 deletion spec/example_app/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.0].define(version: 2024_11_13_130741) do
ActiveRecord::Schema[8.0].define(version: 2025_04_03_192516) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_catalog.plpgsql"

Expand Down Expand Up @@ -94,6 +94,7 @@
t.time "example_time"
t.string "password"
t.boolean "hidden", default: false, null: false
t.string "favourite_color"
end

create_table "line_items", id: :serial, force: :cascade do |t|
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/fields/color_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require "rails_helper"
require "administrate/field/color"

describe Administrate::Field::Color do
describe "#color" do
it "displays the color" do
field = described_class.new(:color, "#FF5733", :show)

prefixes = field.partial_prefixes

expect(prefixes).to eq(["fields/color", "fields/base"])
end
end
end