-
Notifications
You must be signed in to change notification settings - Fork 8
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
Use color palette for color fields in blog category #2022
Merged
jurgenwerk
merged 10 commits into
main
from
cs-7778-use-color-palette-for-color-field-in-blog-category
Jan 12, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1682bc5
Add ColorField, include it in BlogCategory
jurgenwerk b85e751
Merge branch 'main' into cs-7778-use-color-palette-for-color-field-in…
jurgenwerk a697140
Assign colors to blog categories in seed realm
jurgenwerk 9a5b49e
Fix whitespace
jurgenwerk 0e51718
Whitespace fixes
jurgenwerk f5b7d43
Whitespace fix
jurgenwerk 0c6e799
Another whitespace
jurgenwerk ab8a599
Move color fields to /fields folder
jurgenwerk 2920ea3
Merge branch 'main' into cs-7778-use-color-palette-for-color-field-in…
jurgenwerk df38e92
Cleanup
jurgenwerk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { | ||
Component, | ||
FieldDef, | ||
StringField, | ||
contains, | ||
field, | ||
} from 'https://cardstack.com/base/card-api'; | ||
import { ColorPalette } from '@cardstack/boxel-ui/components'; | ||
import { ColorPicker } from '@cardstack/boxel-ui/components'; | ||
|
||
class View extends Component<typeof ColorPalette> { | ||
<template> | ||
<ColorPicker | ||
@color={{@model.hexValue}} | ||
@disabled={{true}} | ||
@showHexString={{true}} | ||
/> | ||
</template> | ||
} | ||
|
||
class EditView extends Component<typeof ColorPalette> { | ||
setColor = (color: string) => { | ||
this.args.model.hexValue = color; | ||
}; | ||
|
||
<template> | ||
<ColorPalette @color={{@model.hexValue}} @onChange={{this.setColor}} /> | ||
</template> | ||
} | ||
|
||
export class ColorField extends FieldDef { | ||
static displayName = 'Color'; | ||
@field hexValue = contains(StringField); | ||
|
||
static isolated = View; | ||
static embedded = View; | ||
static atom = View; | ||
static fitted = View; | ||
static edit = EditView; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
Component, | ||
FieldDef, | ||
StringField, | ||
contains, | ||
field, | ||
} from 'https://cardstack.com/base/card-api'; | ||
import { ColorPalette, ColorPicker } from '@cardstack/boxel-ui/components'; | ||
|
||
class View extends Component<typeof ColorPalette> { | ||
<template> | ||
<ColorPicker | ||
@color={{@model.hexValue}} | ||
@disabled={{true}} | ||
@showHexString={{true}} | ||
/> | ||
</template> | ||
} | ||
|
||
class EditView extends Component<typeof ColorPalette> { | ||
setColor = (color: string) => { | ||
this.args.model.hexValue = color; | ||
}; | ||
|
||
<template> | ||
<ColorPalette @color={{@model.hexValue}} @onChange={{this.setColor}} /> | ||
</template> | ||
} | ||
|
||
export class ColorField extends FieldDef { | ||
static displayName = 'Color'; | ||
@field hexValue = contains(StringField); | ||
|
||
static isolated = View; | ||
static embedded = View; | ||
static atom = View; | ||
static fitted = View; | ||
static edit = EditView; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So this is the default for blog category. If I want a random default similar to how avatar computes the background color. What is the best way to do that? Wud that be an extend of this color field and handle that default internally?
I know I need this in particular use-case. But, I was just wondering if we would handle this in this PR. I think maybe NOT
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.
We could make a function that converts the arbitrary string (category name) to some hex color value, in a deterministic way. And a function that returns a good contrast color to that color, similarly to how the avatar works. Then we could have a computed fields that either returns the computed colors, or user-set colors, in case they set them