Skip to content

Commit

Permalink
meta: some component cleanups and design fixes (nodejs#6046)
Browse files Browse the repository at this point in the history
* chore: simplified button

* refactor: language drop: use external props, onchange and style fixes

* chore: use formatmessage

* meta: normalised component imports

* fix: language dropdown duplicated entries

* meta: update to collab guide
  • Loading branch information
ovflowd authored Oct 25, 2023
1 parent 4cfd688 commit 2defb6e
Show file tree
Hide file tree
Showing 25 changed files with 104 additions and 90 deletions.
2 changes: 1 addition & 1 deletion COLLABORATOR_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ They also allow Developers to preview Components and be able to test them manual

```tsx
import type { Meta as MetaObj, StoryObj } from '@storybook/react';
import NameOfComponent from './index';
import NameOfComponent from '@components/PathTo/YourComponent';

type Story = StoryObj<typeof NameOfComponent>;
type Meta = MetaObj<typeof NameOfComponent>;
Expand Down
3 changes: 1 addition & 2 deletions components/Common/AvatarGroup/Avatar/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import Avatar from '@/components/Common/AvatarGroup/Avatar';
import { githubProfileAvatarUrl } from '@/util/gitHubUtils';

import Avatar from './';

type Story = StoryObj<typeof Avatar>;
type Meta = MetaObj<typeof Avatar>;

Expand Down
3 changes: 1 addition & 2 deletions components/Common/AvatarGroup/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import AvatarGroup from '@/components/Common/AvatarGroup';
import { githubProfileAvatarUrl } from '@/util/gitHubUtils';

import AvatarGroup from './';

type Story = StoryObj<typeof AvatarGroup>;
type Meta = MetaObj<typeof AvatarGroup>;

Expand Down
4 changes: 2 additions & 2 deletions components/Common/AvatarGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import classNames from 'classnames';
import type { ComponentProps, FC } from 'react';
import { useState, useMemo } from 'react';

import Avatar from '@/components/Common/AvatarGroup/Avatar';
import avatarstyles from '@/components/Common/AvatarGroup/Avatar/index.module.css';
import { getAcronymFromString } from '@/util/stringUtils';

import Avatar from './Avatar';
import avatarstyles from './Avatar/index.module.css';
import styles from './index.module.css';

type AvatarGroupProps = {
Expand Down
2 changes: 1 addition & 1 deletion components/Common/Badge/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import Badge from './index';
import Badge from '@/components/Common/Badge';

type Story = StoryObj<typeof Badge>;
type Meta = MetaObj<typeof Badge>;
Expand Down
2 changes: 1 addition & 1 deletion components/Common/Banner/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import Banner from './index';
import Banner from '@/components/Common/Banner';

type Story = StoryObj<typeof Banner>;
type Meta = MetaObj<typeof Banner>;
Expand Down
2 changes: 1 addition & 1 deletion components/Common/Blockquote/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import Blockquote from './index';
import Blockquote from '@/components/Common/Blockquote';

type Story = StoryObj<typeof Blockquote>;
type Meta = MetaObj<typeof Blockquote>;
Expand Down
2 changes: 1 addition & 1 deletion components/Common/Breadcrumbs/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import Breadcrumbs from './';
import Breadcrumbs from '@/components/Common/Breadcrumbs';

type Story = StoryObj<typeof Breadcrumbs>;
type Meta = MetaObj<typeof Breadcrumbs>;
Expand Down
10 changes: 5 additions & 5 deletions components/Common/Breadcrumbs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { type LinkProps } from 'next/link';
import { useMemo, type FC } from 'react';

import BreadcrumbHomeLink from './BreadcrumbHomeLink';
import BreadcrumbItem from './BreadcrumbItem';
import BreadcrumbLink from './BreadcrumbLink';
import BreadcrumbRoot from './BreadcrumbRoot';
import BreadcrumbTruncatedItem from './BreadcrumbTruncatedItem';
import BreadcrumbHomeLink from '@/components/Common/Breadcrumbs/BreadcrumbHomeLink';
import BreadcrumbItem from '@/components/Common/Breadcrumbs/BreadcrumbItem';
import BreadcrumbLink from '@/components/Common/Breadcrumbs/BreadcrumbLink';
import BreadcrumbRoot from '@/components/Common/Breadcrumbs/BreadcrumbRoot';
import BreadcrumbTruncatedItem from '@/components/Common/Breadcrumbs/BreadcrumbTruncatedItem';

type BreadcrumbLink = {
label: string;
Expand Down
2 changes: 1 addition & 1 deletion components/Common/Button/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import Button from './index';
import Button from '@/components/Common/Button';

type Story = StoryObj<typeof Button>;
type Meta = MetaObj<typeof Button>;
Expand Down
17 changes: 8 additions & 9 deletions components/Common/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ const Button: FC<ButtonProps> = ({
children,
className,
...props
}) => {
const buttonStyles = classNames(styles.button, styles[variant], className);

return (
<button className={buttonStyles} {...props}>
{children}
</button>
);
};
}) => (
<button
className={classNames(styles.button, styles[variant], className)}
{...props}
>
{children}
</button>
);

export default Button;
2 changes: 1 addition & 1 deletion components/Common/CrossLink/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import CrossLink from './index';
import CrossLink from '@/components/Common/CrossLink';

type Story = StoryObj<typeof CrossLink>;
type Meta = MetaObj<typeof CrossLink>;
Expand Down
28 changes: 16 additions & 12 deletions components/Common/LanguageDropDown/index.module.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.iconWrapper {
@apply h-9
w-9
rounded-md
bg-neutral-100
p-2
rounded-md
bg-neutral-100
p-2
text-neutral-700
dark:bg-neutral-900
dark:text-neutral-300;
Expand All @@ -12,23 +12,27 @@
.dropDownContent {
@apply max-h-80
w-48
overflow-y-scroll
overflow-hidden
rounded
border
border-neutral-200
py-[1px]
border
border-neutral-200
shadow-lg
dark:border-neutral-900;

> div {
@apply max-h-80
w-48 overflow-y-auto;
}
}

.dropDownItem {
@apply cursor-default
@apply cursor-pointer
px-2.5
py-1.5
text-sm
py-1.5
text-sm
font-medium
text-neutral-800
outline-none
text-neutral-800
outline-none
data-[highlighted]:bg-green-600
data-[highlighted]:text-white
dark:text-white;
Expand Down
13 changes: 11 additions & 2 deletions components/Common/LanguageDropDown/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import LanguageDropDown from './index';
import LanguageDropDown from '@/components/Common/LanguageDropDown';

type Story = StoryObj<typeof LanguageDropDown>;
type Meta = MetaObj<typeof LanguageDropDown>;

export const Default: Story = {};
export const Default: Story = {
args: {
availableLanguages: [
{ name: 'English', code: 'en' },
{ name: 'French', code: 'fr' },
{ name: 'Spanish', code: 'es' },
],
currentLanguage: { name: 'English', code: 'en' },
},
};

export default { component: LanguageDropDown } as Meta;
43 changes: 25 additions & 18 deletions components/Common/LanguageDropDown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,26 @@ import classNames from 'classnames';
import type { FC } from 'react';
import { useIntl } from 'react-intl';

import { useLocale } from '@/hooks/useLocale';
import type { LocaleConfig } from '@/types';

import styles from './index.module.css';

export type LanguageDropDownProps = {
onClick?: () => void;
type SimpleLocaleConfig = Pick<LocaleConfig, 'name' | 'code'>;

type LanguageDropDownProps = {
onChange?: (newLocale: SimpleLocaleConfig) => void;
currentLanguage: SimpleLocaleConfig;
availableLanguages: SimpleLocaleConfig[];
};

const LanguageDropdown: FC<LanguageDropDownProps> = ({
onClick = () => {},
onChange = () => {},
currentLanguage,
availableLanguages,
}) => {
const { availableLocales, currentLocale } = useLocale();
const intl = useIntl();
const { formatMessage } = useIntl();

const ariaLabel = intl.formatMessage({
const ariaLabel = formatMessage({
id: 'components.common.languageDropdown.label',
});

Expand All @@ -36,17 +41,19 @@ const LanguageDropdown: FC<LanguageDropDownProps> = ({
className={styles.dropDownContent}
sideOffset={5}
>
{availableLocales.map(({ name, code }) => (
<DropdownMenu.Item
key={code}
onClick={onClick}
className={classNames(styles.dropDownItem, {
[styles.currentDropDown]: code === currentLocale.code,
})}
>
{name}
</DropdownMenu.Item>
))}
<div>
{availableLanguages.map(({ name, code }) => (
<DropdownMenu.Item
key={code}
onClick={() => onChange({ name, code })}
className={classNames(styles.dropDownItem, {
[styles.currentDropDown]: code === currentLanguage.code,
})}
>
{name}
</DropdownMenu.Item>
))}
</div>
</DropdownMenu.Content>
</DropdownMenu.Portal>
</DropdownMenu.Root>
Expand Down
3 changes: 1 addition & 2 deletions components/Common/MetaBar/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import Image from 'next/image';
import { FormattedMessage } from 'react-intl';

import AvatarGroup from '@/components/Common/AvatarGroup';
import MetaBar from '@/components/Common/MetaBar';
import LocalizedLink from '@/components/LocalizedLink';

import MetaBar from './index';

type Story = StoryObj<typeof MetaBar>;
type Meta = MetaObj<typeof MetaBar>;

Expand Down
2 changes: 1 addition & 1 deletion components/Common/Notification/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CodeBracketIcon } from '@heroicons/react/24/solid';
import type { Meta as MetaObj, StoryObj } from '@storybook/react';
import { FormattedMessage } from 'react-intl';

import Notification from './index';
import Notification from '@/components/Common/Notification';

type Story = StoryObj<typeof Notification>;
type Meta = MetaObj<typeof Notification>;
Expand Down
4 changes: 2 additions & 2 deletions components/Common/Pagination/PaginationListItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const PaginationListItem: FC<PaginationListItemProps> = ({
currentPage,
totalPages,
}) => {
const intl = useIntl();
const { formatMessage } = useIntl();

return (
<li key={pageNumber} aria-setsize={totalPages} aria-posinset={pageNumber}>
<LocalizedLink
href={url}
aria-label={intl.formatMessage(
aria-label={formatMessage(
{ id: 'components.common.pagination.pageLabel' },
{ pageNumber }
)}
Expand Down
2 changes: 1 addition & 1 deletion components/Common/Pagination/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta as MetaObj, StoryObj } from '@storybook/react';

import Pagination from './index';
import Pagination from '@/components/Common/Pagination';

type Story = StoryObj<typeof Pagination>;
type Meta = MetaObj<typeof Pagination>;
Expand Down
10 changes: 5 additions & 5 deletions components/Common/Pagination/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import styles from './index.module.css';

type Page = { url: string };

export type PaginationProps = {
type PaginationProps = {
// One-based number of the current page
currentPage: number;
pages: Page[];
Expand All @@ -23,7 +23,7 @@ const Pagination: FC<PaginationProps> = ({
pages,
currentPageSiblingsCount = 1,
}) => {
const intl = useIntl();
const { formatMessage } = useIntl();

const parsedPages = useGetPageElements(
currentPage,
Expand All @@ -33,14 +33,14 @@ const Pagination: FC<PaginationProps> = ({

return (
<nav
aria-label={intl.formatMessage({
aria-label={formatMessage({
id: 'components.common.pagination.defaultLabel',
})}
className={styles.pagination}
>
<Button
type="button"
aria-label={intl.formatMessage({
aria-label={formatMessage({
id: 'components.common.pagination.prevAriaLabel',
})}
disabled={currentPage === 1}
Expand All @@ -56,7 +56,7 @@ const Pagination: FC<PaginationProps> = ({
<ol className={styles.list}>{parsedPages}</ol>
<Button
type="button"
aria-label={intl.formatMessage({
aria-label={formatMessage({
id: 'components.common.pagination.nextAriaLabel',
})}
disabled={currentPage === pages.length}
Expand Down
Loading

0 comments on commit 2defb6e

Please sign in to comment.