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

Add new "middle-out" order prop option to `OuiPaletteColorBlind' #856

Merged
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: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- Update next light theme primary color to #07827E ([#981](https://github.com/opensearch-project/oui/pull/981))
- Add dismissible prop to OuiCallOut ([#985](https://github.com/opensearch-project/oui/pull/985))
- Adjust background color of OuiToolTip in `next` theme ([#1004](https://github.com/opensearch-project/oui/pull/1004))
- Add new `middle-out` order prop option to `OuiPaletteColorBlind` ([#856](https://github.com/opensearch-project/oui/pull/856))

### 🐛 Bug Fixes

Expand Down
10 changes: 10 additions & 0 deletions src-docs/src/views/color_palette/color_palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ const customPalettes = [
palette: ouiPaletteColorBlind({ rotations: 2 }),
code: 'ouiPaletteColorBlind({rotations: 2})',
},
{
title: 'Lots of colors, with the extremes last',
palette: ouiPaletteColorBlind({
rotations: 9,
direction: 'both',
order: 'middle-out',
}),
code:
"ouiPaletteColorBlind({ rotations: 9, direction: 'both', order: 'middle-out' })",
},
{
title:
'Series may have multiple metrics and so the colors must coordinate but be distinguishable',
Expand Down
4 changes: 2 additions & 2 deletions src-docs/src/views/color_palette/props_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const qualitativePropsInfo = {
},
order: {
description:
'Order similar colors as `group`s or just `append` each variation',
'Order similar colors as `group`s, just `append` each variation (from dark to light), or append from the `middle-out`',
required: false,
type: { name: "'append' | 'group'" },
type: { name: "'append' | 'group' | 'middle-out'" },
defaultValue: { value: "'append'" },
},
direction: {
Expand Down
20 changes: 19 additions & 1 deletion src/services/color/oui_palettes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface OuiPaletteColorBlindProps {
/**
* Order similar colors as `group`s or just `append` each variation
*/
order?: 'append' | 'group';
order?: 'append' | 'group' | 'middle-out';
/**
* Specifies if the direction of the color variations
*/
Expand Down Expand Up @@ -134,6 +134,24 @@ export const ouiPaletteColorBlind = ({
colors.push(...rotation);
}
}

// start with the appended order, then pick from both ends
if (order === 'middle-out') {
const shadePalettes = [];
while (colors.length) {
shadePalettes.push(colors.splice(0, base.length));
}
while (shadePalettes.length) {
const firstPalette = shadePalettes.shift();
if (firstPalette) {
colors.unshift(...firstPalette);
}
const lastPalette = shadePalettes.pop();
if (lastPalette) {
colors.unshift(...lastPalette);
}
}
}
} else {
colors = base;
}
Expand Down