-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add color input #2824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add color input #2824
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -92,6 +92,23 @@ textarea { | |
| width: 100%; | ||
| } | ||
|
|
||
| [type="color"] { | ||
| padding: 0 0.5em; | ||
| } | ||
|
|
||
| .color-example { | ||
| display: flex; | ||
| align-items: center; | ||
|
|
||
| span { | ||
| width: 1em; | ||
| height: 1em; | ||
| line-height: 1.5em; | ||
| display: inline-block; | ||
| margin-right: 0.5em; | ||
| } | ||
| } | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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%; | ||
| } | ||
|
|
||
| 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> |
| 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> |
| 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> |
| 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 |
| 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 |
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I probably could test more....but I added a field in the demo app 😄 |
| 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 |
There was a problem hiding this comment.
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