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

Replace EuiColorPicker with an accessible, custom component #856

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"numeral": "^2.0.6",
"prop-types": "^15.6.0",
"react-ace": "^5.5.0",
"react-color": "^2.13.8",
"react-datepicker": "v1.4.1",
"react-input-autosize": "^2.2.1",
"react-virtualized": "^9.18.5",
Expand Down
26 changes: 23 additions & 3 deletions src-docs/src/views/color_picker/color_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React, {
Component,
} from 'react';

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

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

Expand All @@ -17,6 +18,25 @@ export class ColorPicker extends Component {
};

render() {
return <EuiColorPicker onChange={this.handleChange} color={this.state.color}/>;
const hasErrors = !isValidHex(this.state.color) && (this.state.color !== "");

let errors;
if (hasErrors) {
errors = ['Provide a valid hex value'];
}

return (
<EuiFormRow
label="Pick a color"
isInvalid={hasErrors}
error={errors}
>
<EuiColorPicker
onChange={this.handleChange}
color={this.state.color}
isInvalid={hasErrors}
/>
</EuiFormRow>
);
}
}
56 changes: 0 additions & 56 deletions src-docs/src/views/color_picker/color_picker_clear.js

This file was deleted.

45 changes: 31 additions & 14 deletions src-docs/src/views/color_picker/color_picker_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@ import {
GuideSectionTypes,
} from '../../components';

import {
EuiCode,
} from '../../../../src/components';

import { ColorPicker } from './color_picker';
const colorPickerSource = require('!!raw-loader!./color_picker');
const colorPickerHtml = renderToHtml(ColorPicker);

import { ColorPickerLabelAndClear } from './color_picker_clear';
const colorPickerClearSource = require('!!raw-loader!./color_picker_clear');
const colorPickerClearHtml = renderToHtml(ColorPickerLabelAndClear);
import { CustomSwatches } from './custom_swatches';
const customSwatchesSource = require('!!raw-loader!./custom_swatches');
const customSwatchesHtml = renderToHtml(CustomSwatches);

import { ColorPickerNoColorLabel } from './color_picker_no_color_label';
const colorPickerNoColorLabelSource = require('!!raw-loader!./color_picker_no_color_label');
const colorPickerNoColorLabelHtml = renderToHtml(ColorPickerNoColorLabel);
import { CustomButton } from './custom_button';
const customButtonSource = require('!!raw-loader!./custom_button');
const customButtonHtml = renderToHtml(CustomButton);

export const ColorPickerExample = {
title: 'Color Picker',
Expand All @@ -30,24 +34,37 @@ export const ColorPickerExample = {
}],
demo: <ColorPicker />,
}, {
title: 'With label and reset link',
title: 'Custom color swatches',
source: [{
type: GuideSectionTypes.JS,
code: colorPickerClearSource,
code: customSwatchesSource,
}, {
type: GuideSectionTypes.HTML,
code: colorPickerClearHtml,
code: customSwatchesHtml,
}],
demo: <ColorPickerLabelAndClear />,
text: (
<p>
By default the colors provided are the ten color blind safe visualization colors.
You can however pass in your own color set with the <EuiCode>swatches</EuiCode> prop.
</p>
),
demo: <CustomSwatches />,
}, {
title: 'Without a color label',
title: 'Custom button',
source: [{
type: GuideSectionTypes.JS,
code: colorPickerNoColorLabelSource,
code: customButtonSource,
}, {
type: GuideSectionTypes.HTML,
code: colorPickerNoColorLabelHtml,
code: customButtonHtml,
}],
demo: <ColorPickerNoColorLabel />,
text: (
<p>
You can optionally use a custom button as the trigger for selection using
the <EuiCode>button</EuiCode> prop. Please remember to add accessibility to this
component, using proper button markup and aria labeling.
</p>
),
demo: <CustomButton />,
}],
};
42 changes: 0 additions & 42 deletions src-docs/src/views/color_picker/color_picker_no_color_label.js

This file was deleted.

53 changes: 53 additions & 0 deletions src-docs/src/views/color_picker/custom_button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, {
Component,
} from 'react';

import {
EuiColorPicker,
EuiFormRow,
EuiColorPickerSwatch
} from '../../../../src/components';

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

export class CustomButton 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 !== "");

let errors;
if (hasErrors) {
errors = ['Provide a valid hex value'];
}

return (
<EuiFormRow
label="Pick a color"
isInvalid={hasErrors}
error={errors}
>
<EuiColorPicker
onChange={this.handleChange}
color={this.state.color}
isInvalid={hasErrors}
button={
<EuiColorPickerSwatch
color={this.state.color}
aria-label="Select a new color"
/>
}
/>
</EuiFormRow>
);
}
}
50 changes: 50 additions & 0 deletions src-docs/src/views/color_picker/custom_swatches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React, {
Component,
} from 'react';

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

export class CustomSwatches 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 !== "");

let errors;
if (hasErrors) {
errors = ['Provide a valid hex value'];
}

const customSwatches = [
'#333',
'#666',
'#999',
'#CCC',
]

return (
<EuiFormRow
label="Pick a color"
isInvalid={hasErrors}
error={errors}
>
<EuiColorPicker
onChange={this.handleChange}
color={this.state.color}
isInvalid={hasErrors}
swatches={customSwatches}
/>
</EuiFormRow>
);
}
}
1 change: 1 addition & 0 deletions src-docs/src/views/icon/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const iconTypes = [
'stats',
'stop',
'stopFilled',
'stopSlash',
'storage',
'string',
'temperature',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const OutsideClickDetectorExample = {
text: (
<p>
Use <EuiCode>EuiOutsideClickDetector</EuiCode> to trigger a handler when the user clicks outside of the
child element.
child element. Note that it will not work if the immediate child is a React <EuiCode>Fragment</EuiCode>.
</p>
),
props: { EuiOutsideClickDetector },
Expand Down
Loading