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

[EuiSteps] Add support for unordered steps #7813

Merged
merged 36 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c3f5b96
feat(EuiSteps): enable support for xxs size
mgadewoll Jun 5, 2024
59e1c4b
feat(EuiStepsHorizontal): enable support for xxs size
mgadewoll Jun 5, 2024
2086b2a
docs(storybook): add unordered steps stories
mgadewoll Jun 5, 2024
ebbbc9f
test(VRT): add reference images for added stories
mgadewoll Jun 5, 2024
114537a
test: add unit test for EuiStepNumber xxs size
mgadewoll Jun 5, 2024
0535cd7
chore: cleanup leftover changes
mgadewoll Jun 5, 2024
2c87175
docs: update EUI docs
mgadewoll Jun 5, 2024
b93594c
chore: add changelog
mgadewoll Jun 5, 2024
2bac60c
refactor: rename xxs size to xs size for EuiStepsHorizontal
mgadewoll Jun 6, 2024
612cbfb
docs(storybook): update xxs size to xs
mgadewoll Jun 6, 2024
55f9cb8
remove manual top offset in favor of align-items
mgadewoll Jun 6, 2024
4fb886e
test(VRT): update reference images
mgadewoll Jun 6, 2024
df4bf4f
test: update snapshots
mgadewoll Jun 6, 2024
1fe3b73
chore: update changelog copy
mgadewoll Jun 6, 2024
6b1fc44
refactor: update unnumbered variant fontSize
mgadewoll Jun 6, 2024
ac2fc1c
test(VRT): update reference images
mgadewoll Jun 6, 2024
1225414
docs(storybook): make steps xxs size stories VRT only
mgadewoll Jun 7, 2024
712476c
refactor: rename titleSize xxs to none
mgadewoll Jun 7, 2024
0de2968
refactor: move map to global scope
mgadewoll Jun 7, 2024
5369959
docs(storybook): add options for not resolved titleSize
mgadewoll Jun 7, 2024
ef75535
docs: enhance custom title docs and add xxs size to controls
mgadewoll Jun 7, 2024
791216e
chore: update changelog
mgadewoll Jun 7, 2024
7c212dd
refactor: apply title centering only for xxs size
mgadewoll Jun 7, 2024
50372d9
test(VRT): update reference images
mgadewoll Jun 7, 2024
5b5a82d
shore: revert steps type changes
mgadewoll Jun 10, 2024
f1886a5
refactor: revert back to manual top offset to align number and title
mgadewoll Jun 10, 2024
5f7860b
docs(storybook): add VRT only stories for multiline titles
mgadewoll Jun 10, 2024
718adb7
test(VRT): add reference iamges
mgadewoll Jun 10, 2024
6bfe5c1
test: update snapshots
mgadewoll Jun 10, 2024
26fa851
docs: update docs examples
mgadewoll Jun 10, 2024
7c18aac
chore: update changelog
mgadewoll Jun 10, 2024
24fb024
refactor: remove manual offset in favor of alignment via line-height
mgadewoll Jun 11, 2024
5afbb98
chore: update titleSize type jsdoc
mgadewoll Jun 11, 2024
cf4f312
test(VRT): update reference images
mgadewoll Jun 11, 2024
1a0e945
test: update snapshots
mgadewoll Jun 11, 2024
b55740d
refactor: use step sizes over theme sizes
mgadewoll Jun 12, 2024
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/eui/changelogs/upcoming/7813.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Updated `EuiSteps` to support a new `titleSize="xxs"` style, which outputs the same title font size but smaller unnumbered step indicators
- Updated `EuiStepsHorizontal` to support a new `size="xs"` style, which outputs smaller unnumbered step indicators
- Updated `EuiStepNumber` to support new `titleSize="none"` which omits rendering step numbers, and will only render icons
23 changes: 15 additions & 8 deletions packages/eui/src-docs/src/views/steps/steps_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,21 @@ export const StepsExample = {
},
],
text: (
<p>
You can set a different title size using <EuiCode>titleSize</EuiCode>.
If <EuiCode>titleSize</EuiCode> is set in both{' '}
<strong>EuiSteps</strong> and <strong>EuiStep</strong>, the latter
value will override the former. Additionally, the title size{' '}
<EuiCode>xs</EuiCode> will automatically generate smaller steps
circles.
</p>
<>
<p>
You can set a different title size using{' '}
<EuiCode>titleSize</EuiCode>. If <EuiCode>titleSize</EuiCode> is set
in both <strong>EuiSteps</strong> and <strong>EuiStep</strong>, the
latter value will override the former. Additionally, the title size{' '}
<EuiCode>xs</EuiCode> will automatically generate smaller steps
circles.
</p>
<p>
The title size <EuiCode>xxs</EuiCode> affects only the size of the
accompanying <strong>unnumbered</strong> step indicator, but not the
title itself.
</p>
</>
),
demo: <StepsTitleSizes />,
snippet: stepsTitleSizesSnippet,
Expand Down
4 changes: 4 additions & 0 deletions packages/eui/src-docs/src/views/steps/steps_horizontal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export default () => {
];

const sizeButtons = [
{
id: 'xs',
label: 'XSmall',
},
{
id: 's',
label: 'Small',
Expand Down
67 changes: 59 additions & 8 deletions packages/eui/src-docs/src/views/steps/steps_title_sizes.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,77 @@
import React from 'react';
import React, { useState } from 'react';

import { EuiCode, EuiSteps } from '../../../../src/components';
import {
EuiButtonGroup,
EuiCode,
EuiSpacer,
EuiSteps,
EuiTitle,
} from '../../../../src/components';
import { EuiStepInterface } from '../../../../src/components/steps/step';

const firstSetOfSteps = [
const firstSetOfSteps: EuiStepInterface[] = [
{
title: 'Step 1',
children: (
<p>
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
Steps with <EuiCode>titleSize</EuiCode> set to <EuiCode>xs</EuiCode>{' '}
like this one, get a smaller step circle
Both step title and circle indicators will adjust in size based on the{' '}
<EuiCode>titleSize</EuiCode> prop
</p>
),
},
{
title: 'Step 2',
children: (
<p>
Steps with <EuiCode>titleSize</EuiCode> set to <EuiCode>xs</EuiCode>{' '}
like this one, get a smaller step circle
Both step title and circle indicators will adjust in size based on the{' '}
<EuiCode>titleSize</EuiCode> prop
</p>
),
},
];

export default () => <EuiSteps titleSize="xs" steps={firstSetOfSteps} />;
const sizeButtons = [
{
id: 'xxs',
label: 'XXSmall',
},
{
id: 'xs',
label: 'XSmall',
},
{
id: 's',
label: 'Small',
},
{
id: 'm',
label: 'Medium',
},
];

type StepSizes = NonNullable<EuiStepInterface['titleSize']>;

export default () => {
const [titleSize, setTitleSize] = useState<StepSizes>('m');

const sizeOnChange = (optionId: StepSizes) => {
setTitleSize(optionId);
};

return (
<>
<EuiTitle size="xxs">
<h3>Step Size</h3>
</EuiTitle>
<EuiSpacer size="s" />
<EuiButtonGroup
legend="Horizontal step size toggle"
options={sizeButtons}
idSelected={titleSize}
onChange={(id) => sizeOnChange(id as StepSizes)}
/>
<EuiSpacer size="m" />
<EuiSteps titleSize={titleSize} steps={firstSetOfSteps} />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,27 @@ exports[`EuiStepHorizontal props size s is rendered 1`] = `
</button>
`;

exports[`EuiStepHorizontal props size xs is rendered 1`] = `
<button
class="euiStepHorizontal emotion-euiStepHorizontal-enabled"
data-step-status="incomplete"
title="Step 1 is incomplete"
>
<span
class="euiStepNumber euiStepHorizontal__number emotion-euiStepNumber-none-incomplete-euiStepHorizontal__number"
>
<span
class="emotion-euiScreenReaderOnly"
>
Step 1 is incomplete
</span>
</span>
<span
class="euiStepHorizontal__title emotion-euiStepHorizontal__title"
/>
</button>
`;

exports[`EuiStepHorizontal props status complete is rendered 1`] = `
<button
class="euiStepHorizontal emotion-euiStepHorizontal-enabled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@ exports[`EuiStepNumber is rendered 1`] = `
</span>
`;

exports[`EuiStepNumber props has titleSize is rendered 1`] = `
<span
class="euiStepNumber emotion-euiStepNumber-xs"
>
<span
class="emotion-euiScreenReaderOnly"
>
Step 1
</span>
<span
aria-hidden="true"
class="euiStepNumber__number emotion-euiStepNumber__number"
>
1
</span>
</span>
`;

exports[`EuiStepNumber props status complete is rendered 1`] = `
<span
class="euiStepNumber emotion-euiStepNumber-s-complete"
Expand Down Expand Up @@ -145,3 +127,21 @@ exports[`EuiStepNumber props status warning is rendered 1`] = `
</span>
</span>
`;

exports[`EuiStepNumber props titleSize is rendered 1`] = `
<span
class="euiStepNumber emotion-euiStepNumber-xs"
>
<span
class="emotion-euiScreenReaderOnly"
>
Step 1
</span>
<span
aria-hidden="true"
class="euiStepNumber__number emotion-euiStepNumber__number"
>
1
</span>
</span>
`;
31 changes: 31 additions & 0 deletions packages/eui/src/components/steps/step.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
* Side Public License, v 1.
*/

import React from 'react';
import type { Meta, StoryObj } from '@storybook/react';
import { faker } from '@faker-js/faker';

import { hideStorybookControls } from '../../../.storybook/utils';
import { STATUS } from './step_number';
import { EuiStep, EuiStepProps } from './step';

faker.seed(42);

const meta: Meta<EuiStepProps> = {
title: 'Navigation/EuiSteps/EuiSteps/EuiStep',
component: EuiStep,
Expand All @@ -35,3 +39,30 @@ export const Playground: Story = {
children: 'lorem ipsum',
},
};

export const MultilineTitle: Story = {
tags: ['vrt-only'],
args: {
title: faker.lorem.words(7),
children: 'lorem ipsum',
},
render: (args) => <ComponentStep {...args} />,
};

export const MultilineTitleXXS: Story = {
tags: ['vrt-only'],
args: {
title: faker.lorem.words(13),
children: 'lorem ipsum',
titleSize: 'xxs',
},
render: (args) => <ComponentStep {...args} />,
};

const ComponentStep = (props: EuiStepProps) => {
return (
<div css={{ width: '400px' }}>
<EuiStep {...props} />
</div>
);
};
24 changes: 24 additions & 0 deletions packages/eui/src/components/steps/step.styles.ts
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const euiStepVariables = (euiTheme: UseEuiTheme['euiTheme']) => {
return {
numberSize: euiTheme.size.xl,
numberXSSize: euiTheme.size.l,
numberXXSSize: euiTheme.size.base,
numberMargin: euiTheme.size.base,
};
};
Expand Down Expand Up @@ -66,6 +67,11 @@ export const euiStepStyles = (euiThemeContext: UseEuiTheme) => {
background-position: -${euiTheme.size.xs} ${euiTheme.size.l};
}
`,
xxs: css`
&:not(:last-of-type) {
background-position: -${euiTheme.size.s} ${euiTheme.size.base};
mgadewoll marked this conversation as resolved.
Show resolved Hide resolved
}
`,
};
};

Expand Down Expand Up @@ -118,6 +124,21 @@ export const euiStepContentStyles = (euiThemeContext: UseEuiTheme) => {
mathWithUnits(euiStep.numberXSSize, (x) => x / 2)
)}
`,
xxs: css`
/* Align the content's contents with the title */
${logicalCSS(
'padding-left',
mathWithUnits(
[euiStep.numberXXSSize, euiStep.numberMargin],
(x, y) => x / 2 + y
)
)}
/* Align content border to horizontal center of step number */
${logicalCSS(
'margin-left',
mathWithUnits(euiStep.numberXXSSize, (x) => x / 2)
)}
`,
};
};

Expand All @@ -142,5 +163,8 @@ export const euiStepTitleStyles = (euiThemeContext: UseEuiTheme) => {
${logicalCSS('padding-top', euiTheme.size.xs)}
`,
xs: css``,
xxs: css`
line-height: ${euiStep.numberXXSSize};
`,
};
};
16 changes: 11 additions & 5 deletions packages/eui/src/components/steps/step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import React, {
ReactNode,
} from 'react';
import { CommonProps } from '../common';
import { EuiTitle, EuiTitleProps, EuiTitleSize } from '../title';
import { EuiTitle, EuiTitleProps } from '../title';
import { EuiStepNumber, EuiStepStatus } from './step_number';
import { useEuiTheme } from '../../services';
import {
Expand Down Expand Up @@ -42,9 +42,11 @@ export interface EuiStepInterface {
*/
status?: EuiStepStatus;
/**
* Title sizing equivalent to EuiTitle, but only `m`, `s` and `xs`. Defaults to `s`
* Title sizing equivalent to **EuiTitle**, but only `m`, `s`, `xs` font sizes.
* The `xxs` size reduces the size of the accompanying step indicator, but not the title itself.
* @default s
*/
titleSize?: Exclude<EuiTitleProps['size'], 'xxxs' | 'xxs' | 'l'>;
titleSize?: Extract<EuiTitleProps['size'], 'xxs' | 'xs' | 's' | 'm'>;
}

export type EuiStepProps = CommonProps &
Expand Down Expand Up @@ -84,9 +86,13 @@ export const EuiStep: FunctionComponent<EuiStepProps> = ({
return (
<div className={classes} css={cssStyles} {...rest}>
<div className="euiStep__titleWrapper" css={cssTitleWrapperStyles}>
<EuiStepNumber number={step} status={status} titleSize={titleSize} />
<EuiStepNumber
number={step}
status={status}
titleSize={titleSize === 'xxs' ? 'none' : titleSize}
/>
<EuiTitle
size={titleSize as EuiTitleSize}
size={titleSize === 'xxs' ? 'xs' : titleSize}
className="euiStep__title"
css={cssStepTitleStyles}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export const euiStepHorizontalStyles = (euiThemeContext: UseEuiTheme) => {
// Adjust the size of the step number and connecting lines based on size
m: _generateStepSizeAndInset(euiStep.numberSize),
s: _generateStepSizeAndInset(euiStep.numberXSSize),
xs: _generateStepSizeAndInset(euiStep.numberXXSSize),
// Note: these selectors must be nested because focus/hover state
// is on the parent container, but affects specific children
enabled: css`
Expand Down
17 changes: 14 additions & 3 deletions packages/eui/src/components/steps/step_horizontal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ import React, {
MouseEventHandler,
} from 'react';
import { CommonProps } from '../common';
import { EuiStepNumber, EuiStepStatus } from './step_number';
import { useEuiTheme } from '../../services';
import {
EuiStepNumber,
EuiStepNumberProps,
EuiStepStatus,
} from './step_number';
import { EuiStepsHorizontalSizes } from './steps_horizontal';
import {
useI18nCompleteStep,
Expand All @@ -26,7 +31,6 @@ import {
useI18nErrorsStep,
useI18nLoadingStep,
} from './step_strings';
import { useEuiTheme } from '../../services';
import {
euiStepHorizontalStyles,
euiStepHorizontalNumberStyles,
Expand Down Expand Up @@ -55,6 +59,13 @@ export interface EuiStepHorizontalProps
size?: EuiStepsHorizontalSizes;
}

// The titleSize map is not 1 to 1; small == xs on the titleSize map
const stepNumberSizeMap: Record<string, EuiStepNumberProps['titleSize']> = {
xs: 'none',
s: 'xs',
m: 'm',
};

export const EuiStepHorizontal: FunctionComponent<EuiStepHorizontalProps> = ({
className,
step = 1,
Expand Down Expand Up @@ -119,7 +130,7 @@ export const EuiStepHorizontal: FunctionComponent<EuiStepHorizontalProps> = ({
className="euiStepHorizontal__number"
status={status}
number={step}
titleSize={size === 's' ? 'xs' : 'm'} // The titleSize map is not 1 to 1; small == xs on the titleSize map
titleSize={stepNumberSizeMap[size]}
css={cssNumberStyles}
/>

Expand Down
Loading
Loading