Skip to content
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

EuiColorPicker inline and TS conversion #2340

Merged
merged 10 commits into from
Sep 16, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src-docs/src/views/color_picker/color_picker_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ const modesPickerSnippet = `// Gradient map only
/>
`;

import { Inline } from './inline';
const inlineSource = require('!!raw-loader!./inline');
const inlineHtml = renderToHtml(Inline);
const inlineSnippet = `<EuiColorPicker
onChange={handleChange}
color={chosenColor}
isInvalid={hasErrors}
inline={true}
/>
`;

import Containers from './containers';
const containersSource = require('!!raw-loader!./containers');
const containersHtml = renderToHtml(Containers);
Expand Down Expand Up @@ -215,6 +226,27 @@ export const ColorPickerExample = {
snippet: [modesSwatchSnippet, modesPickerSnippet],
demo: <Modes />,
},
{
title: 'Inline',
source: [
{
type: GuideSectionTypes.JS,
code: inlineSource,
},
{
type: GuideSectionTypes.HTML,
code: inlineHtml,
},
],
text: (
<p>
Use the <EuiCode>inline</EuiCode> prop to display the color picker
without an input or popover.
</p>
),
snippet: inlineSnippet,
demo: <Inline />,
},
{
title: 'Containers',
source: [
Expand Down
30 changes: 30 additions & 0 deletions src-docs/src/views/color_picker/inline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { Component } from 'react';

import { EuiColorPicker } from '../../../../src/components';
import { isValidHex } from '../../../../src/services';

export class Inline extends Component {
constructor(props) {
super(props);
this.state = {
color: '',
};
}

handleChange = value => {
this.setState({ color: value });
};

render() {
const hasErrors = !isValidHex(this.state.color) && this.state.color !== '';

return (
<EuiColorPicker
onChange={this.handleChange}
color={this.state.color}
isInvalid={hasErrors}
inline={true}
/>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,189 @@ exports[`renders fullWidth EuiColorPicker 1`] = `
</div>
`;

exports[`renders inline EuiColorPicker 1`] = `
<div
class="euiColorPicker testClass1 testClass2"
>
<div>
<div
aria-activedescendant="undefined-saturationIndicator"
aria-describedby="undefined-saturationDescription"
aria-roledescription="HSV color mode saturation and value selection"
class="euiSaturation"
data-test-subj="euiSaturation"
role="application"
style="background:hsl(30, 100%, 50%)"
tabindex="0"
>
<p
class="euiScreenReaderOnly"
>
Use the arrow keys to navigate the square color gradient. The coordinates resulting from each key press will be used to calculate HSV color mode 'saturation' and 'value' numbers, in the range of 0 to 1. Left and right decrease and increase (respectively) the 'saturation' value. Up and down decrease and increase (respectively) the 'value' value.
</p>
<p
aria-live="polite"
class="euiScreenReaderOnly"
>
#ffeedd
</p>
<div
class="euiSaturation__lightness"
>
<div
class="euiSaturation__saturation"
/>
</div>
<div
class="euiSaturation__indicator"
id="undefined-saturationIndicator"
style="left:0;top:0"
/>
</div>
<label
class="euiScreenReaderOnly"
for="undefined-hue"
>
Select the HSV color mode 'hue' value
</label>
<p
aria-live="polite"
class="euiScreenReaderOnly"
>
#ffeedd
</p>
<div
class="euiHue"
>
<input
class="euiHue__range"
id="undefined-hue"
max="360"
min="0"
step="1"
type="range"
value="30"
/>
</div>
</div>
<div
class="euiFlexGroup euiFlexGroup--gutterSmall euiFlexGroup--directionRow euiFlexGroup--wrap"
role="listbox"
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
aria-label="Select #00B3A4 as the color"
class="euiColorPickerSwatch euiColorPicker__swatchSelect"
role="option"
style="background:#00B3A4"
type="button"
/>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
aria-label="Select #3185FC as the color"
class="euiColorPickerSwatch euiColorPicker__swatchSelect"
role="option"
style="background:#3185FC"
type="button"
/>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
aria-label="Select #DB1374 as the color"
class="euiColorPickerSwatch euiColorPicker__swatchSelect"
role="option"
style="background:#DB1374"
type="button"
/>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
aria-label="Select #490092 as the color"
class="euiColorPickerSwatch euiColorPicker__swatchSelect"
role="option"
style="background:#490092"
type="button"
/>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
aria-label="Select #FEB6DB as the color"
class="euiColorPickerSwatch euiColorPicker__swatchSelect"
role="option"
style="background:#FEB6DB"
type="button"
/>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
aria-label="Select #E6C220 as the color"
class="euiColorPickerSwatch euiColorPicker__swatchSelect"
role="option"
style="background:#E6C220"
type="button"
/>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
aria-label="Select #F98510 as the color"
class="euiColorPickerSwatch euiColorPicker__swatchSelect"
role="option"
style="background:#F98510"
type="button"
/>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
aria-label="Select #BFA180 as the color"
class="euiColorPickerSwatch euiColorPicker__swatchSelect"
role="option"
style="background:#BFA180"
type="button"
/>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
aria-label="Select #461A0A as the color"
class="euiColorPickerSwatch euiColorPicker__swatchSelect"
role="option"
style="background:#461A0A"
type="button"
/>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
aria-label="Select #920000 as the color"
class="euiColorPickerSwatch euiColorPicker__swatchSelect"
role="option"
style="background:#920000"
type="button"
/>
</div>
</div>
</div>
`;

exports[`renders readOnly EuiColorPicker 1`] = `
<div
class="euiPopover euiPopover--anchorDownLeft euiPopover--displayBlock"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ import { VISUALIZATION_COLORS, keyCodes } from '../../services';
import { requiredProps, findTestSubject, sleep } from '../../test';

jest.mock('../portal', () => ({
// @ts-ignore
EuiPortal: ({ children }) => children,
}));

let onChange;

beforeEach(() => {
onChange = jest.fn();
});
const onChange = jest.fn();

test('renders EuiColorPicker', () => {
const colorPicker = render(
Expand Down Expand Up @@ -70,6 +67,18 @@ test('renders disabled EuiColorPicker', () => {
expect(colorPicker).toMatchSnapshot();
});

test('renders inline EuiColorPicker', () => {
const colorPicker = render(
<EuiColorPicker
onChange={onChange}
color="#ffeedd"
inline={true}
{...requiredProps}
/>
);
expect(colorPicker).toMatchSnapshot();
});

test('renders EuiColorPicker with an empty swatch when color is null', () => {
const colorPicker = render(
<EuiColorPicker onChange={onChange} color={null} {...requiredProps} />
Expand Down
Loading