Skip to content

Commit

Permalink
Merge branch 'main' into rm-eui-chart-theme
Browse files Browse the repository at this point in the history
  • Loading branch information
nickofthyme committed Mar 13, 2024
2 parents 7ba4c15 + 6c86d6e commit 0879994
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/community_contribution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-writing-an-environment-variable-to-github_env
run: |
DATA=$(
curl -L -i -w "%{http_code}" \
curl -L -i -g -w "%{http_code}" \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.EUI_COMMUNITY_PR }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
Expand Down
3 changes: 3 additions & 0 deletions changelogs/upcoming/7570.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Deprecations**

- Deprecated `euiPalettePositive` and `euiPaletteNegative` in favour of a more culturally inclusive `euiPaletteGreen` and `euiPaletteRed`
1 change: 1 addition & 0 deletions changelogs/upcoming/7575.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Enhanced `EuiResizeObserver` and `useResizeObserver`'s performance to not trigger page reflows on resize event
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import {
euiPaletteForTemperature,
euiPaletteCool,
euiPaletteWarm,
euiPaletteNegative,
euiPalettePositive,
euiPaletteRed,
euiPaletteGreen,
euiPaletteGray,
} from '../../../../src/services';
const paletteData = {
euiPaletteForStatus,
euiPaletteForTemperature,
euiPaletteComplementary,
euiPaletteNegative,
euiPalettePositive,
euiPaletteRed,
euiPaletteGreen,
euiPaletteCool,
euiPaletteWarm,
euiPaletteGray,
Expand Down
8 changes: 4 additions & 4 deletions src-docs/src/views/color_picker/color_palette_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
euiPaletteForStatus,
euiPaletteForTemperature,
euiPaletteComplementary,
euiPaletteNegative,
euiPalettePositive,
euiPaletteRed,
euiPaletteGreen,
euiPaletteCool,
euiPaletteWarm,
euiPaletteGray,
Expand Down Expand Up @@ -50,8 +50,8 @@ const paletteData = {
euiPaletteForStatus,
euiPaletteForTemperature,
euiPaletteComplementary,
euiPaletteNegative,
euiPalettePositive,
euiPaletteRed,
euiPaletteGreen,
euiPaletteCool,
euiPaletteWarm,
euiPaletteGray,
Expand Down
6 changes: 3 additions & 3 deletions src-docs/src/views/elastic_charts/accessibility_bullet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Chart, Settings, Goal } from '@elastic/charts';
import { EuiSpacer, EuiTitle } from '../../../../src/components';
import {
htmlIdGenerator,
euiPalettePositive,
euiPaletteGreen,
colorPalette,
euiPaletteGray,
useEuiTheme,
Expand All @@ -19,8 +19,8 @@ export default () => {
const bandLabels = ['freezing', 'cold', 'brisk', 'warm', 'hot'];
const bands = [0, 100, 125, 150, 250];

let spectrum = euiPalettePositive(5);
// For dark theme, start with the brightest positive color and create a palette that goes to dark gray instead of light
let spectrum = euiPaletteGreen(5);
// For dark theme, start with the brightest green color and create a palette that goes to dark gray instead of light
if (isDarkTheme) {
spectrum = colorPalette([spectrum[4], euiPaletteGray(5)[4]], 5).reverse();
}
Expand Down
4 changes: 2 additions & 2 deletions src-docs/src/views/elastic_charts/goal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EuiSpacer, EuiTitle, EuiCodeBlock } from '../../../../src/components';
import {
htmlIdGenerator,
useIsWithinBreakpoints,
euiPalettePositive,
euiPaletteGreen,
} from '../../../../src/services';
import { EuiFlexGrid, EuiFlexItem } from '../../../../src/components/flex';
import { useChartBaseTheme } from './utils/use_chart_base_theme';
Expand All @@ -17,7 +17,7 @@ export const GoalChart = () => {
const bandLabels = ['', 'freezing', 'cold', 'warm', 'hot'];
const bands = [-10, 0, 15, 25, 40];

const spectrum = euiPalettePositive(5);
const spectrum = euiPaletteGreen(5);
const opacityMapHex: Record<number, string> = {
'-10': spectrum[0],
'0': spectrum[1],
Expand Down
8 changes: 4 additions & 4 deletions src-docs/src/views/elastic_charts/theming.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
euiPaletteForTemperature,
euiPaletteCool,
euiPaletteWarm,
euiPaletteNegative,
euiPalettePositive,
euiPaletteRed,
euiPaletteGreen,
euiPaletteGray,
} from '../../../../src/services';
import { useChartBaseTheme } from './utils/use_chart_base_theme';
Expand All @@ -34,8 +34,8 @@ const paletteData = {
euiPaletteForStatus,
euiPaletteForTemperature,
euiPaletteComplementary,
euiPaletteNegative,
euiPalettePositive,
euiPaletteRed,
euiPaletteGreen,
euiPaletteCool,
euiPaletteWarm,
euiPaletteGray,
Expand Down
4 changes: 2 additions & 2 deletions src-docs/src/views/elastic_charts/theming_categorical.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { CHART_COMPONENTS, type ChartType, ChartCard } from './shared';
import {
euiPaletteColorBlind,
euiPalettePositive,
euiPaletteGreen,
euiPaletteForStatus,
euiPaletteGray,
} from '../../../../src/services';
Expand Down Expand Up @@ -108,7 +108,7 @@ export default () => {
};

const createQuantityChart = (numCharts: number) => {
const vizColors = euiPalettePositive(numCharts);
const vizColors = euiPaletteGreen(numCharts);

// convert series labels to percentages
const dg = new DataGenerator();
Expand Down
26 changes: 16 additions & 10 deletions src-docs/src/views/elastic_charts/theming_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,22 @@ const chartBaseTheme = isDarkTheme ? DARK_THEME : LIGHT_THEME;

<EuiCodeBlock language="javascript" isCopyable fontSize="s">
{`import { DARK_THEME, LIGHT_THEME } from '@elastic/charts';
import { euiPalettePositive } from '../../../../src/services';
import { euiPaletteGreen } from '../../../../src/services';
const customColors = {
colors: {
vizColors: euiPalettePositive(5),
},
};
<Settings baseTheme={colorMode === 'DARK' ? DARK_THEME : LIGHT_THEME} theme={[customColors]} />`}
const MyChart = () => {
const customColors = {
colors: {
vizColors: euiPaletteGreen(5),
},
};
const chartBaseTheme = isDarkTheme ? DARK_THEME : LIGHT_THEME;
return (
<Chart>
<Settings baseTheme={chartBaseTheme} theme={customColors} />
//...
</Chart>
);
};`}
</EuiCodeBlock>
<p>You&apos;ll find an example of these in the demo below.</p>
</>
Expand Down Expand Up @@ -135,8 +142,7 @@ const customColors = {
a single color that spans from light colors for low amounts to dark
colors for high amounts. If the data signifies{' '}
<strong>trends</strong>, use a two-color divergent scheme, with the
darkest colors at the extremes. Remember that red means bad/negative
and green is good/positive.
darkest colors at the extremes.
</p>
<p>
Whan signifying quantities, group values into intervals instead of a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import {
euiPaletteForStatus,
euiPaletteForTemperature,
euiPaletteGray,
euiPaletteNegative,
euiPalettePositive,
euiPaletteRed,
euiPaletteGreen,
euiPaletteWarm,
} from '../../../../src/services';
import { getDefaultEuiMarkdownUiPlugins } from '../../../../src/components/markdown_editor';
Expand All @@ -49,8 +49,8 @@ const paletteData = {
euiPaletteForStatus,
euiPaletteForTemperature,
euiPaletteComplementary,
euiPaletteNegative,
euiPalettePositive,
euiPaletteRed,
euiPaletteGreen,
euiPaletteCool,
euiPaletteWarm,
euiPaletteGray,
Expand Down
6 changes: 4 additions & 2 deletions src-docs/src/views/tables/actions/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@ export default () => {

const selection: EuiTableSelectionType<User> = {
selectable: (user: User) => user.online,
selectableMessage: (selectable: boolean) =>
!selectable ? 'User is currently offline' : '',
selectableMessage: (selectable: boolean, user: User) =>
!selectable
? `${user.firstName} ${user.lastName} is currently offline`
: `Select ${user.firstName} ${user.lastName}`,
onSelectionChange,
};

Expand Down
6 changes: 4 additions & 2 deletions src-docs/src/views/tables/expanding_rows/expanding_rows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ export default () => {

const selection: EuiTableSelectionType<User> = {
selectable: (user: User) => user.online,
selectableMessage: (selectable: boolean) =>
!selectable ? 'User is currently offline' : '',
selectableMessage: (selectable: boolean, user: User) =>
!selectable
? `${user.firstName} ${user.lastName} is currently offline`
: `Select ${user.firstName} ${user.lastName}`,
onSelectionChange,
};

Expand Down
6 changes: 4 additions & 2 deletions src-docs/src/views/tables/footer/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ export default () => {

const selection: EuiTableSelectionType<User> = {
selectable: (user: User) => user.online,
selectableMessage: (selectable: boolean) =>
!selectable ? 'User is currently offline' : '',
selectableMessage: (selectable: boolean, user: User) =>
!selectable
? `${user.firstName} ${user.lastName} is currently offline`
: `Select ${user.firstName} ${user.lastName}`,
onSelectionChange,
};

Expand Down
6 changes: 4 additions & 2 deletions src-docs/src/views/tables/mobile/mobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ export default () => {

const selection: EuiTableSelectionType<User> = {
selectable: (user: User) => user.online,
selectableMessage: (selectable: boolean) =>
!selectable ? 'User is currently offline' : '',
selectableMessage: (selectable: boolean, user: User) =>
!selectable
? `${user.firstName} ${user.lastName} is currently offline`
: `Select ${user.firstName} ${user.lastName}`,
onSelectionChange,
};

Expand Down
6 changes: 4 additions & 2 deletions src-docs/src/views/tables/selection/selection_controlled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@ export default () => {

const selection: EuiTableSelectionType<User> = {
selectable: (user: User) => user.online,
selectableMessage: (selectable: boolean) =>
!selectable ? 'User is currently offline' : '',
selectableMessage: (selectable: boolean, user: User) =>
!selectable
? `${user.firstName} ${user.lastName} is currently offline`
: `Select ${user.firstName} ${user.lastName}`,
onSelectionChange,
selected: selectedItems,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ export default () => {

const selection: EuiTableSelectionType<User> = {
selectable: (user: User) => user.online,
selectableMessage: (selectable: boolean) =>
!selectable ? 'User is currently offline' : '',
selectableMessage: (selectable: boolean, user: User) =>
!selectable
? `${user.firstName} ${user.lastName} is currently offline`
: `Select ${user.firstName} ${user.lastName}`,
onSelectionChange,
initialSelected: onlineUsers,
};
Expand Down
28 changes: 7 additions & 21 deletions src/components/observer/resize_observer/resize_observer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ export class EuiResizeObserver extends EuiObserver<EuiResizeObserverProps> {
width: 0,
};

onResize: ResizeObserverCallback = () => {
// `entry.contentRect` provides incomplete `height` and `width` data.
// Use `getBoundingClientRect` to account for padding and border.
// https://developer.mozilla.org/en-US/docs/Web/API/DOMRectReadOnly
if (!this.childNode) return;
const { height, width } = this.childNode.getBoundingClientRect();
onResize: ResizeObserverCallback = ([entry]) => {
const { inlineSize: width, blockSize: height } = entry.borderBoxSize[0];

// Check for actual resize event
if (this.state.height === height && this.state.width === width) {
return;
Expand Down Expand Up @@ -94,22 +91,11 @@ export const useResizeObserver = (

useEffect(() => {
if (container != null) {
// ResizeObserver's first call to the observation callback is scheduled in the future
// so find the container's initial dimensions now
const boundingRect = container.getBoundingClientRect();
setSize({
width: boundingRect.width,
height: boundingRect.height,
});

const observer = makeResizeObserver(container, () => {
// `entry.contentRect` provides incomplete `height` and `width` data.
// Use `getBoundingClientRect` to account for padding and border.
// https://developer.mozilla.org/en-US/docs/Web/API/DOMRectReadOnly
const { height, width } = container.getBoundingClientRect();
const observer = makeResizeObserver(container, ([entry]) => {
const { inlineSize, blockSize } = entry.borderBoxSize[0];
setSize({
width,
height,
width: inlineSize,
height: blockSize,
});
});

Expand Down
Loading

0 comments on commit 0879994

Please sign in to comment.