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 4 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

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.

3 participants