Skip to content

Commit

Permalink
Text as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabetdev committed May 8, 2020
1 parent 01b88f8 commit c3ae30b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src-docs/src/views/color_picker/color_palette_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ const palettes: EuiColorPalettePickerPaletteProps[] = [
palette: ['rgba(0, 0, 0, 0.5)', 'rgba(255, 255, 255, 0.2)'],
type: 'fixed',
},
{
value: 'custom',
title: 'Just a text as an option',
type: 'text',
},
];

export const ColorPalettePicker = () => {
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/color_picker/color_picker_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const colorPalettePickerSnippet = `<EuiColorPalettePicker
value: 'palette1',
title: 'Palette 1',
palette: ['#ff3f3f', '#ffcc06'],
type: 'stops',
type: 'fixed',
},
]}
onChange={onPaletteChange}
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/color_picker/props.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FunctionComponent } from 'react';

import { EuiColorPalettePickerPaletteProps } from '../../../../src/components/color_picker/';
import { EuiColorPalettePickerPaletteProps } from '../../../../src/components/color_picker/color_palette_picker';

export const EuiColorPalettePickerPalette: FunctionComponent<
EuiColorPalettePickerPaletteProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ export interface EuiColorPalettePickerPaletteProps {
* Specify if the palette is
* `fixed`: individual color blocks; or
* `gradient`: each color fades into the next
* `text`: a text as an option. A title is required.
*/
type: 'fixed' | 'gradient';
type: 'fixed' | 'gradient' | 'text';
/**
* Array of color `strings` or `ColorStops` in the form of
* { stop: number, color: string }
*/
palette: string[] | ColorStop[];
palette?: string[] | ColorStop[];
}

export type EuiColorPalettePickerProps = CommonProps & {
Expand Down Expand Up @@ -112,18 +113,18 @@ export const EuiColorPalettePicker: FunctionComponent<
);
};

const getButton = (title: any) => title;
const getText = (title: any) => title;

const paletteOptions = palettes.map((item: any) => {
return {
value: String(item.value),
inputDisplay:
item.type !== 'button'
item.type !== 'text'
? getPalette(item.palette, item.type)
: getButton(item.title),
: getText(item.title),
dropdownDisplay: (
<EuiFlexGroup gutterSize="xs" direction="column">
{item.title && item.type !== 'button' && (
{item.title && item.type !== 'text' && (
<EuiFlexItem>
<EuiText
size="xs"
Expand All @@ -134,9 +135,9 @@ export const EuiColorPalettePicker: FunctionComponent<
)}

<EuiFlexItem>
{item.type !== 'button'
{item.type !== 'text'
? getPalette(item.palette, item.type)
: getButton(item.title)}
: getText(item.title)}
</EuiFlexItem>
</EuiFlexGroup>
),
Expand Down

0 comments on commit c3ae30b

Please sign in to comment.