From 203751f40f2c09cec2e50e16a1a5132485dc6004 Mon Sep 17 00:00:00 2001 From: Matic Jurglic Date: Mon, 6 Jan 2025 21:28:19 +0100 Subject: [PATCH 01/13] Add color picker to boxel ui --- .../src/components/color-picker/index.gts | 76 +++++++++++++++++++ .../src/components/color-picker/usage.gts | 50 ++++++++++++ packages/boxel-ui/addon/src/usage.ts | 2 + 3 files changed, 128 insertions(+) create mode 100644 packages/boxel-ui/addon/src/components/color-picker/index.gts create mode 100644 packages/boxel-ui/addon/src/components/color-picker/usage.gts diff --git a/packages/boxel-ui/addon/src/components/color-picker/index.gts b/packages/boxel-ui/addon/src/components/color-picker/index.gts new file mode 100644 index 0000000000..f013830c66 --- /dev/null +++ b/packages/boxel-ui/addon/src/components/color-picker/index.gts @@ -0,0 +1,76 @@ +import { on } from '@ember/modifier'; +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; + +interface Signature { + Args: { + onChange: (color: string) => void; + value: string; + }; + Element: HTMLDivElement; +} + +export default class ColorPicker extends Component { + @tracked private selectedColor: string; + + constructor(owner: unknown, args: Signature['Args']) { + super(owner, args); + this.selectedColor = args.value ?? '#000000'; + } + + private handleColorChange = (event: Event) => { + const input = event.target as HTMLInputElement; + this.selectedColor = input.value; + this.args.onChange(input.value); + }; + + +} diff --git a/packages/boxel-ui/addon/src/components/color-picker/usage.gts b/packages/boxel-ui/addon/src/components/color-picker/usage.gts new file mode 100644 index 0000000000..27f8049d6a --- /dev/null +++ b/packages/boxel-ui/addon/src/components/color-picker/usage.gts @@ -0,0 +1,50 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import ColorPicker from './index.gts'; + +export default class ColorPickerUsage extends Component { + @tracked color = '#ff0000'; + + private onChange = (newColor: string) => { + this.color = newColor; + }; + + +} diff --git a/packages/boxel-ui/addon/src/usage.ts b/packages/boxel-ui/addon/src/usage.ts index 20c32ff9ff..6a69b52761 100644 --- a/packages/boxel-ui/addon/src/usage.ts +++ b/packages/boxel-ui/addon/src/usage.ts @@ -38,6 +38,7 @@ import SwitchUsage from './components/switch/usage.gts'; import TabbedHeaderUsage from './components/tabbed-header/usage.gts'; import TooltipUsage from './components/tooltip/usage.gts'; import ViewSelectorUsage from './components/view-selector/usage.gts'; +import ColorPickerUsage from './components/color-picker/usage.gts'; export const ALL_USAGE_COMPONENTS = [ ['Accordion', AccordionUsage], @@ -77,4 +78,5 @@ export const ALL_USAGE_COMPONENTS = [ ['TabbedHeader', TabbedHeaderUsage], ['Tooltip', TooltipUsage], ['ViewSelector', ViewSelectorUsage], + ['ColorPicker', ColorPickerUsage], ]; From 689a71cd8e21f0d21ef904b0c262b9c719908ef6 Mon Sep 17 00:00:00 2001 From: Matic Jurglic Date: Tue, 7 Jan 2025 14:16:30 +0100 Subject: [PATCH 02/13] Improve ColorPicker and add ColorPalette --- packages/boxel-ui/addon/src/components.ts | 4 + .../src/components/color-palette/index.gts | 128 ++++++++++++++++++ .../src/components/color-palette/usage.gts | 44 ++++++ .../src/components/color-picker/index.gts | 47 +++---- .../src/components/color-picker/usage.gts | 84 +++++++----- packages/boxel-ui/addon/src/usage.ts | 2 + 6 files changed, 247 insertions(+), 62 deletions(-) create mode 100644 packages/boxel-ui/addon/src/components/color-palette/index.gts create mode 100644 packages/boxel-ui/addon/src/components/color-palette/usage.gts diff --git a/packages/boxel-ui/addon/src/components.ts b/packages/boxel-ui/addon/src/components.ts index 6bd10aae3e..05f79ba72a 100644 --- a/packages/boxel-ui/addon/src/components.ts +++ b/packages/boxel-ui/addon/src/components.ts @@ -8,6 +8,8 @@ import CardContainer from './components/card-container/index.gts'; import CardContentContainer from './components/card-content-container/index.gts'; import CardHeader from './components/card-header/index.gts'; import CircleSpinner from './components/circle-spinner/index.gts'; +import ColorPalette from './components/color-palette/index.gts'; +import ColorPicker from './components/color-picker/index.gts'; import DateRangePicker from './components/date-range-picker/index.gts'; import DndKanbanBoard, { type DndItem, @@ -78,6 +80,8 @@ export { CardContentContainer, CardHeader, CircleSpinner, + ColorPalette, + ColorPicker, DateRangePicker, DndColumn, DndItem, diff --git a/packages/boxel-ui/addon/src/components/color-palette/index.gts b/packages/boxel-ui/addon/src/components/color-palette/index.gts new file mode 100644 index 0000000000..5977a9c9b1 --- /dev/null +++ b/packages/boxel-ui/addon/src/components/color-palette/index.gts @@ -0,0 +1,128 @@ +import Component from '@glimmer/component'; +import { on } from '@ember/modifier'; +import { eq } from '@cardstack/boxel-ui/helpers'; +import { fn } from '@ember/helper'; +import ColorPicker from '../color-picker/index.gts'; + +interface Signature { + Args: { + color: string; + onChange: (color: string) => void; + }; + Element: HTMLDivElement; +} + +const DEFAULT_PALETTE_COLORS = [ + // Row 1 + '#000000', + '#777777', + '#FA2200', + '#FA7F01', + '#FBEB06', + '#1EDF67', + '#39B1FF', + '#9D00FF', + // Row 2 + '#A6A6A6', + '#CFCFCF', + '#FCA6A7', + '#FCD2A7', + '#FCF8A6', + '#A6F4CA', + '#A7E4FF', + '#DEA6FF', +]; + +export default class ColorPalette extends Component { + colors = DEFAULT_PALETTE_COLORS; + + private openColorPicker = (event: MouseEvent) => { + let container = event.currentTarget as HTMLElement; + let input = container.querySelector('input[type="color"]'); + if (!input) { + throw new Error('Color picker input not found'); + } + (input as HTMLInputElement).click(); + }; + + +} diff --git a/packages/boxel-ui/addon/src/components/color-palette/usage.gts b/packages/boxel-ui/addon/src/components/color-palette/usage.gts new file mode 100644 index 0000000000..dfd73ed667 --- /dev/null +++ b/packages/boxel-ui/addon/src/components/color-palette/usage.gts @@ -0,0 +1,44 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import ColorPalette from './index.gts'; +import FreestyleUsage from 'ember-freestyle/components/freestyle/usage'; +import { fn } from '@ember/helper'; + +export default class ColorPaletteUsage extends Component { + @tracked color = '#000000'; + + private handleColorChange = (newColor: string) => { + this.color = newColor; + }; + + +} diff --git a/packages/boxel-ui/addon/src/components/color-picker/index.gts b/packages/boxel-ui/addon/src/components/color-picker/index.gts index f013830c66..184f8365cb 100644 --- a/packages/boxel-ui/addon/src/components/color-picker/index.gts +++ b/packages/boxel-ui/addon/src/components/color-picker/index.gts @@ -1,26 +1,19 @@ import { on } from '@ember/modifier'; import Component from '@glimmer/component'; -import { tracked } from '@glimmer/tracking'; interface Signature { Args: { + color: string; + disabled?: boolean; onChange: (color: string) => void; - value: string; + showHexString?: boolean; }; Element: HTMLDivElement; } export default class ColorPicker extends Component { - @tracked private selectedColor: string; - - constructor(owner: unknown, args: Signature['Args']) { - super(owner, args); - this.selectedColor = args.value ?? '#000000'; - } - private handleColorChange = (event: Event) => { - const input = event.target as HTMLInputElement; - this.selectedColor = input.value; + let input = event.target as HTMLInputElement; this.args.onChange(input.value); }; @@ -28,26 +21,35 @@ export default class ColorPicker extends Component {
+ {{#if @showHexString}} + {{@color}} + {{/if}}
+ + <:example> + + + + <:api as |Args|> + + + + + + } diff --git a/packages/boxel-ui/addon/src/usage.ts b/packages/boxel-ui/addon/src/usage.ts index 6a69b52761..e1880e60cf 100644 --- a/packages/boxel-ui/addon/src/usage.ts +++ b/packages/boxel-ui/addon/src/usage.ts @@ -39,6 +39,7 @@ import TabbedHeaderUsage from './components/tabbed-header/usage.gts'; import TooltipUsage from './components/tooltip/usage.gts'; import ViewSelectorUsage from './components/view-selector/usage.gts'; import ColorPickerUsage from './components/color-picker/usage.gts'; +import ColorPaletteUsage from './components/color-palette/usage.gts'; export const ALL_USAGE_COMPONENTS = [ ['Accordion', AccordionUsage], @@ -79,4 +80,5 @@ export const ALL_USAGE_COMPONENTS = [ ['Tooltip', TooltipUsage], ['ViewSelector', ViewSelectorUsage], ['ColorPicker', ColorPickerUsage], + ['ColorPalette', ColorPaletteUsage], ]; From e1d8094a2f5b3d5447d8a7810953771fdd48ba98 Mon Sep 17 00:00:00 2001 From: Matic Jurglic Date: Tue, 7 Jan 2025 14:46:43 +0100 Subject: [PATCH 03/13] Accessibility fixes --- .../src/components/color-palette/index.gts | 22 +++++++------------ .../src/components/color-picker/index.gts | 10 ++++++++- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/boxel-ui/addon/src/components/color-palette/index.gts b/packages/boxel-ui/addon/src/components/color-palette/index.gts index 5977a9c9b1..cec6df3287 100644 --- a/packages/boxel-ui/addon/src/components/color-palette/index.gts +++ b/packages/boxel-ui/addon/src/components/color-palette/index.gts @@ -1,8 +1,8 @@ -import Component from '@glimmer/component'; -import { on } from '@ember/modifier'; import { eq } from '@cardstack/boxel-ui/helpers'; import { fn } from '@ember/helper'; +import { on } from '@ember/modifier'; import ColorPicker from '../color-picker/index.gts'; +import Component from '@glimmer/component'; interface Signature { Args: { @@ -37,12 +37,9 @@ export default class ColorPalette extends Component { colors = DEFAULT_PALETTE_COLORS; private openColorPicker = (event: MouseEvent) => { - let container = event.currentTarget as HTMLElement; - let input = container.querySelector('input[type="color"]'); - if (!input) { - throw new Error('Color picker input not found'); - } - (input as HTMLInputElement).click(); + const container = event.currentTarget as HTMLElement; + const input = container.querySelector('input[type="color"]'); + input?.click(); }; } From 1ee5467b441396968c22bf4836ca31a65e0b72d0 Mon Sep 17 00:00:00 2001 From: Matic Jurglic Date: Tue, 7 Jan 2025 16:19:58 +0100 Subject: [PATCH 09/13] Compose the 2 components --- .../addon/src/components/color-palette/index.gts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/boxel-ui/addon/src/components/color-palette/index.gts b/packages/boxel-ui/addon/src/components/color-palette/index.gts index f304dee4a1..556807f216 100644 --- a/packages/boxel-ui/addon/src/components/color-palette/index.gts +++ b/packages/boxel-ui/addon/src/components/color-palette/index.gts @@ -3,6 +3,7 @@ import { concat, fn } from '@ember/helper'; import { on } from '@ember/modifier'; import { htmlSafe } from '@ember/template'; import Component from '@glimmer/component'; +import ColorPicker from '../color-picker/index.gts'; interface Signature { Args: { @@ -57,13 +58,7 @@ export default class ColorPalette extends Component { From 985a142110f8c3d8636b16231120cdd0151473d6 Mon Sep 17 00:00:00 2001 From: Matic Jurglic Date: Tue, 7 Jan 2025 16:26:05 +0100 Subject: [PATCH 10/13] Not needed --- .../boxel-ui/addon/src/components/color-palette/index.gts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/boxel-ui/addon/src/components/color-palette/index.gts b/packages/boxel-ui/addon/src/components/color-palette/index.gts index 556807f216..7665b09ace 100644 --- a/packages/boxel-ui/addon/src/components/color-palette/index.gts +++ b/packages/boxel-ui/addon/src/components/color-palette/index.gts @@ -37,11 +37,6 @@ const DEFAULT_PALETTE_COLORS = [ export default class ColorPalette extends Component { colors = DEFAULT_PALETTE_COLORS; - private handleColorInput = (event: Event) => { - let input = event.target as HTMLInputElement; - this.args.onChange(input.value); - }; -