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

feat: create Stepper component #2098

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bityutskiyAO
Copy link

  • create Stepper component
  • create stories for Stepper
  • add README files for both languages (en, ru)

@gravity-ui-bot
Copy link
Contributor

Preview is ready.

@gravity-ui-bot
Copy link
Contributor

Visual Tests Report is ready.

@bityutskiyAO bityutskiyAO force-pushed the feat/create-stepper-component branch from 0a4369b to 9d1480e Compare February 7, 2025 14:56
| qa | `data-qa` HTML attribute, used for testing. | `string` | |
| separator | Custom separator node. | `React.ReactNode` | |
| className | CSS class name for the element. | `string` | |
| style | Sets the inline style for the element. | `CSSProperties` | |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may clarify that we are talking about a container

background-color: var(--g-color-base-generic);
}

&__text {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not valid naming according to bem methodology. There we have &__item__text, block in a block. Could add it as a separate block?

@include mixins.overflow-ellipsis();
}

&__icon {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same issue about block in a block

@@ -0,0 +1,23 @@
import type {StepperItemProps} from '../StepperItem';

export const useRelativeSteps = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this code doesn't used. Why we need it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we talking about 2 types of steps "relative" and "non relative", we discuss, that it may be helpfull for end-users to have this hook for auto disabling steps after selected

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip it for the first iteration because we don't know real user cases

};

return (
<button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use gravity Button here

separator?: React.ReactNode;
};

export const StepperSeparator = ({separator}: StepperSeparatorProps) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use smth like BreadcrumbsSeparator

}

export const Stepper = (props: StepperProps) => {
const {children, value = 0, size = 's', className, onUpdate, separator} = props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use component without initial value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u mean without value = 0? I guess, it can

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. So, it looks like an uncontrolled state if we need to set value=undefined, otherwise we need some special value to have such behaviour in controlled state

}, [children, value, size, onUpdate, separator]);

return (
<ol className={b(null, className)} style={props.style} data-qa={props.qa}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Component can receive DOMProps and AriaLabelingProps, but u don't use it here. U can get Breadcrumbs as an example

separator?: React.ReactNode;
}

function Item(_props: StepperItemProps): React.ReactElement | null {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this component, so u can use StepperItem directly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to remove it, but it usefull because of the fact, that i need to add some props to StepperItem (selected, onUpdate, size) that should not be directly accessible via StepItem (root component pass it)

const stepItems = React.useMemo(() => {
const items: React.ReactElement<StepperItemProps>[] = [];

React.Children.forEach(children, (child, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need this logic? I think we can get all the children and StepperSeparator ti them without cloning them

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

export interface StepperProps extends DOMProps, AriaLabelingProps, QAProps {
children: React.ReactElement<StepperItemProps> | React.ReactElement<StepperItemProps>[];
value?: number | string;
onUpdate: (id?: number | string) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why onUpdate is required?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I make it required because of the fact, that without it consumer of the component doesn't have any information about current selected step, it become fully uncontrolled and selection logic won't work (we don't have any inner state for now)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after all - i make it optional

Stepper.Item = Item;
Stepper.displayName = 'Stepper';

export default Stepper;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use default exports


function Item(_props: StepperItemProps): React.ReactElement | null {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using StepperItem inself and clone while mapping children?

onClick={onClick}
disabled={disabled}
size={size}
view={selectedItem ? 'outlined-info' : 'outlined'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it to be a brand color, not info?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In figma we have --g-color-line-info for selected item, should it be changed to brand?

const selectedItem = id === selected;

return (
<Button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's proxy all button props, including all html attributes. It would be a nice feature to wrap items with tooltips or other floating content:

<Stepper>
  <Tooltip>
    <Stepper.Item>...</Stepper.Item>
  </Tooltip>
</Stepper>

import type {StepperItemView} from './types';
import {b} from './utils';

import './Stepper.scss';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already imported this in Stepper.tsx


import {b} from './utils';

import './Stepper.scss';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already imported this in Stepper.tsx

export const Size = {
render: (args) => {
return (
<Flex direction="column" gap={4}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use Showcase component for that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are u mean to move this code to custom Showcase component?

export const StepperSeparator = ({separator}: StepperSeparatorProps) => {
return (
<div className={b('separator')} aria-hidden={true}>
{separator ?? <Icon data={ChevronRight} />}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use useDirection to support RTL and change the default icon to ChevronLeft

Comment on lines 14 to 15
flex-wrap: nowrap;
overflow-x: auto;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need these styles? This cause focus ring to be clipped

@bityutskiyAO bityutskiyAO force-pushed the feat/create-stepper-component branch from 90cf55e to bc8e38c Compare March 4, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants