-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
ColorPicker
to 2024-01 calendar version (#1625)
* chore: add ColorPicker to ui-extensions admin surface * chore: add ColorPicker to ui-extensions-react admin surface * chore: generate patch changeset * chore: add onChange prop to ColorPickerProps
- Loading branch information
1 parent
ca68ac4
commit 29625d1
Showing
10 changed files
with
145 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@shopify/ui-extensions': patch | ||
'@shopify/ui-extensions-react': patch | ||
--- | ||
|
||
Add ColorPicker remote component |
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
9 changes: 9 additions & 0 deletions
9
packages/ui-extensions-react/src/surfaces/admin/components/ColorPicker/ColorPicker.ts
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,9 @@ | ||
import {ColorPicker as BaseColorPicker} from '@shopify/ui-extensions/admin'; | ||
import type {ColorPickerProps} from '@shopify/ui-extensions/admin'; | ||
import {createRemoteReactComponent} from '@remote-ui/react'; | ||
|
||
export const ColorPicker = createRemoteReactComponent< | ||
'ColorPicker', | ||
ColorPickerProps | ||
>(BaseColorPicker); | ||
export type {ColorPickerProps} from '@shopify/ui-extensions/admin'; |
17 changes: 17 additions & 0 deletions
17
...ns-react/src/surfaces/admin/components/ColorPicker/examples/basic-ColorPicker.example.tsx
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,17 @@ | ||
import { | ||
render, | ||
ColorPicker, | ||
} from '@shopify/ui-extensions-react/admin'; | ||
|
||
render('Playground', () => <App />); | ||
|
||
function App() { | ||
return ( | ||
<ColorPicker | ||
value="rgba(255 0 0 / 0.5)" | ||
onChange={(value) => { | ||
console.log({value}); | ||
}} | ||
/> | ||
); | ||
} |
Binary file added
BIN
+103 KB
packages/ui-extensions/docs/surfaces/admin/screenshots/colorpicker-default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+90.3 KB
packages/ui-extensions/docs/surfaces/admin/screenshots/colorpicker-thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
47 changes: 47 additions & 0 deletions
47
packages/ui-extensions/src/surfaces/admin/components/ColorPicker/ColorPicker.doc.ts
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,47 @@ | ||
import {ReferenceEntityTemplateSchema} from '@shopify/generate-docs'; | ||
|
||
const data: ReferenceEntityTemplateSchema = { | ||
name: 'ColorPicker', | ||
description: 'Use this component if you need to select a color.', | ||
requires: '', | ||
thumbnail: 'colorpicker-thumbnail.png', | ||
isVisualComponent: true, | ||
type: '', | ||
definitions: [ | ||
{ | ||
title: 'ColorPickerProps', | ||
description: '', | ||
type: 'ColorPickerProps', | ||
}, | ||
], | ||
category: 'Components', | ||
subCategory: 'Forms', | ||
defaultExample: { | ||
image: 'colorpicker-default.png', | ||
codeblock: { | ||
title: 'Simple ColorPicker example', | ||
tabs: [ | ||
{ | ||
title: 'React', | ||
code: '../../../../../../ui-extensions-react/src/surfaces/admin/components/ColorPicker/examples/basic-ColorPicker.example.tsx', | ||
language: 'tsx', | ||
}, | ||
{ | ||
title: 'JS', | ||
code: './examples/basic-ColorPicker.example.ts', | ||
language: 'js', | ||
}, | ||
], | ||
}, | ||
}, | ||
|
||
related: [ | ||
{ | ||
type: 'component', | ||
name: 'Select', | ||
url: '/docs/api/admin-extensions/components/forms/select', | ||
}, | ||
], | ||
}; | ||
|
||
export default data; |
43 changes: 43 additions & 0 deletions
43
packages/ui-extensions/src/surfaces/admin/components/ColorPicker/ColorPicker.ts
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,43 @@ | ||
import {createRemoteComponent} from '@remote-ui/core'; | ||
|
||
export interface ColorPickerProps { | ||
/** ID for the element. */ | ||
id?: string; | ||
|
||
/** | ||
* Allow user to select an alpha value. | ||
* @default false | ||
*/ | ||
allowAlpha?: boolean; | ||
|
||
/** | ||
* The `onChange` handler will emit the value in hex. | ||
* If the `allowAlpha` prop is `true`, `onChange` will emit an 8-value hex (#RRGGBBAA). | ||
* If the `allowAlpha` prop is `false`, `onChange` will emit a 6-value hex (#RRGGBB). | ||
*/ | ||
onChange?(value: string): void; | ||
|
||
/** | ||
* The currently selected color. | ||
* | ||
* Supported formats include: | ||
* - RGB @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb | ||
* - RGBA @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb | ||
* - Hex (3-value, 4-value, 6-value, 8-value) @see https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color | ||
* | ||
* For RGB and RGBA, both the legacy syntax (comma-separated) and modern syntax (space-separate) are supported. | ||
* @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb | ||
* | ||
* If the value is invalid, the component will select rgb(0, 0, 0). | ||
* | ||
* The `onChange` handler will emit the value in hex. | ||
* If the `allowAlpha` prop is `true`, `onChange` will emit an 8-value hex (#RRGGBBAA). | ||
* If the `allowAlpha` prop is `false`, `onChange` will emit a 6-value hex (#RRGGBB). | ||
*/ | ||
value?: string; | ||
} | ||
|
||
export const ColorPicker = createRemoteComponent< | ||
'ColorPicker', | ||
ColorPickerProps | ||
>('ColorPicker'); |
19 changes: 19 additions & 0 deletions
19
...xtensions/src/surfaces/admin/components/ColorPicker/examples/basic-ColorPicker.example.ts
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,19 @@ | ||
import { | ||
extension, | ||
ColorPicker, | ||
} from '@shopify/ui-extensions/admin'; | ||
|
||
export default extension( | ||
'Playground', | ||
(root) => { | ||
const blockStack = root.createComponent( | ||
ColorPicker, | ||
{ | ||
value: "rgba(255 0 0 / 0.5)", | ||
label: "" | ||
}, | ||
); | ||
|
||
root.appendChild(blockStack); | ||
}, | ||
); |