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: Introduce alignment to Dropdown component #DS-1411 #1837

Open
wants to merge 3 commits into
base: integration/header
Choose a base branch
from

Conversation

crishpeen
Copy link
Member

Description

We need this for Dropdown in Header Navigation.

Additional context

Issue reference

@crishpeen crishpeen added the run-visual-tests Runs visual regression testing on this PR label Jan 8, 2025
Copy link

netlify bot commented Jan 8, 2025

Deploy Preview for spirit-design-system ready!

Name Link
🔨 Latest commit a500b28
🔍 Latest deploy log https://app.netlify.com/sites/spirit-design-system/deploys/677e859007479e00088d64e4
😎 Deploy Preview https://deploy-preview-1837--spirit-design-system.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 96 (no change from production)
Accessibility: 91 (no change from production)
Best Practices: 100 (no change from production)
SEO: 91 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added the feature New feature or request label Jan 8, 2025
@crishpeen crishpeen force-pushed the feature/dropdown-alignment branch from 6d3becd to a43b7c7 Compare January 8, 2025 12:11
Copy link

netlify bot commented Jan 8, 2025

Deploy Preview for spirit-design-system-storybook ready!

Name Link
🔨 Latest commit 6d3becd
🔍 Latest deploy log https://app.netlify.com/sites/spirit-design-system-storybook/deploys/677e6adfcd55470008a457d6
😎 Deploy Preview https://deploy-preview-1837--spirit-design-system-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@coveralls
Copy link

coveralls commented Jan 8, 2025

Coverage Status

coverage: 79.469%. remained the same
when pulling a43b7c7 on feature/dropdown-alignment
into fc5ceb3 on integration/header.

Copy link

netlify bot commented Jan 8, 2025

Deploy Preview for spirit-design-system-storybook canceled.

Name Link
🔨 Latest commit a500b28
🔍 Latest deploy log https://app.netlify.com/sites/spirit-design-system-storybook/deploys/677e8590bba5d5000857bb65

Copy link
Contributor

github-actions bot commented Jan 8, 2025

@crishpeen crishpeen force-pushed the feature/dropdown-alignment branch from a43b7c7 to a500b28 Compare January 8, 2025 14:02

fireEvent.click(trigger);

expect(onToggle).toHaveBeenCalled();
});

it('should render with horizontal alignment', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be more efficient via dataProvider and it.each?

<Item elementType="a" href="#" label="Something else here" />
</DropdownPopover>
</Dropdown>
<div className="px-800 py-1700 bg-tertiary text-center">This a big unrelated box</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

Box component? :D

Copy link
Contributor

@adamkudrna adamkudrna left a comment

Choose a reason for hiding this comment

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

I'd only like to clarify the nullability of alignment, otherwise ✅ for me.


<div class="Container">

<h2 class="docs-Heading">Alignment</h2>
Copy link
Contributor

Choose a reason for hiding this comment

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

It's rather an edge-case prop, but I'd consider placing this demo right after the "Placement" section.

</div>
</div>
<div class="px-800 py-1700 bg-tertiary text-center">
This a big unrelated box
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This a big unrelated box
This is a big unrelated box to demonstrate the alignment

or

Suggested change
This a big unrelated box
This is a big unrelated box to demonstrate the Dropdown Trigger alignment

@@ -254,6 +254,38 @@ See the [Item][item] component for more information.
DropdownPopover implements the [Placement Dictionary][dictionary-placement] for placement. The dictionary values are used as
a value of data attribute `data-spirit-placement`, e.g. `data-spirit-placement="top"`, `data-spirit-placement="right-end"`, etc.

## Alignment

Dropdown supports the extended [Alignment Dictionary][dictionary-alignment] for alignment on both axis. To use it, add the
Copy link
Contributor

Choose a reason for hiding this comment

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

Plural?

Suggested change
Dropdown supports the extended [Alignment Dictionary][dictionary-alignment] for alignment on both axis. To use it, add the
Dropdown supports the extended [Alignment Dictionary][dictionary-alignment] for alignment on both axes. To use it, add the

specific class to the `.Dropdown` element, e.g. `.Dropdown--alignmentXRight` or `.Dropdown--alignmentYStretch`. Adding
any of these classes will make the element display as `flex`.

We also support responsive infix for alignment classes. To use them, add the infix to the class name, e.g. `.Dropdown--tablet--alignmentXRight`.
Copy link
Contributor

Choose a reason for hiding this comment

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

infixes … them ?

Comment on lines +57 to +58
| `alignmentX` | \[ [AlignmentXExtended dictionary][dictionary-alignment] \| `object`] | `null` | ✕ | Apply vertical alignment to trigger, use object to set responsive values, e.g. `{ mobile: 'left', tablet: 'center', desktop: 'right' }` |
| `alignmentY` | \[ [AlignmentYExtended dictionary][dictionary-alignment] \| `object`] | `null` | ✕ | Apply horizontal alignment to trigger, use object to set responsive values, e.g. `{ mobile: 'top', tablet: 'center', desktop: 'bottom' }` |
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the props intentionally nullable? Do we have it like this in other components with alignment?

Comment on lines +10 to +12
.Dropdown[class*='--alignment'] {
display: flex;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This relates to my question about nullable alignment: if you only define alignment for some breakpoints, display flex will be applied in all of them. Is it safe? 🤔

{%- set _classNames = [ _rootClassName, _styleProps.className ] -%}

{%- set _alignmentXClasses = [] -%}
{%- if _alignmentX is iterable and _alignmentX is not null -%}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the second condition necessary? Can an iterable variable be null? 🤔

Comment on lines +2 to +10
import {
AlignmentXExtendedDictionaryType,
AlignmentYExtendedDictionaryType,
Booleanish,
ChildrenProps,
ClickEvent,
PlacementDictionaryType,
StyleProps,
} from './shared';
Copy link
Contributor

Choose a reason for hiding this comment

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

Sigh: If Prettier didn't change formatting here, we could quickly see which imports are new… 🤷🏻‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can still change the line width to 80 chars :-) But base on 🔤 order, first two ;-)

import { useClassNamePrefix } from '../../hooks';
import { DropdownStyleProps } from '../../types';
import { useAlignmentClass, useClassNamePrefix } from '../../hooks';
import { DropdownStyleProps, GridAlignmentXType, GridAlignmentYType } from '../../types';
Copy link
Contributor

Choose a reason for hiding this comment

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

Grid alignment types? Is it correct in Dropdown? 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this needs to be refactored.

@@ -18,11 +26,23 @@ export type DropdownTriggerRenderProps = {
ref: LegacyRef<HTMLButtonElement & HTMLAnchorElement>;
};

export interface DropdownProps extends ChildrenProps, StyleProps {
export type DropdownAlignmentXType =
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion (if-minor): If DropdownAlignment and the GridAlignment dictionaries/types are the same, maybe we should refactor them and not copy and rename them.

@literat
Copy link
Collaborator

literat commented Jan 10, 2025

Screenshot 2025-01-10 at 13 32 30

Are we able to present this feature a little bit better, please? This looks like a bug, IMHO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request run-visual-tests Runs visual regression testing on this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants