Skip to content

Commit

Permalink
feat: new dropdown component
Browse files Browse the repository at this point in the history
  • Loading branch information
astagi authored Feb 19, 2024
1 parent 8849308 commit 6a02102
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 134 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/pc-update.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

name: Publiccode.yml update

on:
schedule:
- cron: '30 17 * * *'
- cron: '30 17 * * *'

workflow_dispatch:

Expand All @@ -21,5 +20,5 @@ jobs:
uses: peter-evans/create-pull-request@v3
if: failure()
with:
title: "chore: update software version ${{ steps.pva.outputs.version }} and date in publiccode.yml"
title: 'chore: update software version ${{ steps.pva.outputs.version }} and date in publiccode.yml'
branch: feature/publiccode-${{ steps.pva.outputs.version }}
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@
* numeric input component ([d4a299c](https://github.com/italia/design-react-kit/commit/d4a299cb43ad138352deab45d552bd33a3be3b19))



6 changes: 3 additions & 3 deletions README.EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ yarn install react react-dom

👉🏻 You can contribute to the library in various ways:

* With your own code, taking charge of an issue among those open and not already assigned among [the issues](https://github.com/italia/design-react-kit/issues) of React Kit (even a comment on the issue to notify the desire to take charge).
* By reporting bugs or improvements to the React Kit [official repository](https://github.com/italia/design-react-kit/).
* By writing to us on the [dedicated channel](https://developersitalia.slack.com/messages/C04J92F9XM2/) of Slack.
- With your own code, taking charge of an issue among those open and not already assigned among [the issues](https://github.com/italia/design-react-kit/issues) of React Kit (even a comment on the issue to notify the desire to take charge).
- By reporting bugs or improvements to the React Kit [official repository](https://github.com/italia/design-react-kit/).
- By writing to us on the [dedicated channel](https://developersitalia.slack.com/messages/C04J92F9XM2/) of Slack.

## How to contribute with your own code

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ yarn install react react-dom

👉🏻 È possibile contribuire alla libreria in vari modi:

* Con il proprio codice, prendendo in carico una issue tra quelle aperte e non già assegnate tra [le issue](https://github.com/italia/design-react-kit/issues) di React Kit (è sufficiente anche un commento sulla issue per notificare la volontà di presa in carico).
* Attraverso la segnalazione di bug o miglioramenti al [repository ufficiale](https://github.com/italia/design-react-kit/) di React Kit.
* Scrivendoci sul [canale dedicato](https://developersitalia.slack.com/messages/C04J92F9XM2/) di Slack.
- Con il proprio codice, prendendo in carico una issue tra quelle aperte e non già assegnate tra [le issue](https://github.com/italia/design-react-kit/issues) di React Kit (è sufficiente anche un commento sulla issue per notificare la volontà di presa in carico).
- Attraverso la segnalazione di bug o miglioramenti al [repository ufficiale](https://github.com/italia/design-react-kit/) di React Kit.
- Scrivendoci sul [canale dedicato](https://developersitalia.slack.com/messages/C04J92F9XM2/) di Slack.

## Come contribuire con il codice

Vorresti dare una mano su Design React Kit? **Sei nel posto giusto!**

Se non l'hai già fatto, inizia spendendo qualche minuto per approfondire la tua conoscenza sulle
[linee guida di design per i servizi web della PA](https://design-italia.readthedocs.io/it/stable/index.html),
e fai riferimento alle [indicazioni su come contribuire a Design React Kit](https://github.com/italia/design-react-kit/blob/main/CONTRIBUTING.md).
Expand All @@ -146,11 +146,11 @@ I requisiti minimi del tuo ambiente locale devono essere:
- Yarn

Clona il repository ed esegui `yarn` per installare le dipendenze.
Quindi esegui
Quindi esegui

```sh
yarn storybook:serve
```
```

per avviare il server di sviluppo.

Expand Down
35 changes: 35 additions & 0 deletions src/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { ElementType, FC, HTMLAttributes } from 'react';
import classNames from 'classnames';

export interface DropdownProps extends HTMLAttributes<HTMLElement> {
tag?: ElementType;
inNavbar?: boolean;
textCenter?: boolean;
/** Classi aggiuntive da usare per il componente Button */
className?: string;
testId?: string;
}

export const Dropdown: FC<DropdownProps> = ({
className,
testId,
tag,
children,
inNavbar,
textCenter,
...attributes
}) => {
const classes = classNames(className, {
dropdown: true,
'text-center': textCenter,
'nav-item': inNavbar
});

const Tag = tag !== undefined ? tag : 'div';

return (
<Tag className={classes} data-testid={testId} {...attributes}>
{children}
</Tag>
);
};
20 changes: 20 additions & 0 deletions src/Dropdown/DropdownMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { FC, HTMLAttributes } from 'react';
import classNames from 'classnames';

export interface DropdownMenuProps extends HTMLAttributes<HTMLElement> {
/** Classi aggiuntive da usare per il componente Button */
className?: string;
testId?: string;
}

export const DropdownMenu: FC<DropdownMenuProps> = ({ className, testId, children, ...attributes }) => {
const classes = classNames(className, {
'dropdown-menu': true
});

return (
<div className={classes} data-testid={testId} {...attributes}>
{children}
</div>
);
};
63 changes: 63 additions & 0 deletions src/Dropdown/DropdownToggle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { ElementType, FC, HTMLAttributes, useEffect, useRef } from 'react';
import classNames from 'classnames';
import { Dropdown } from 'bootstrap-italia';
import { Icon } from '../Icon/Icon';
import { Button } from '../Button/Button';

export interface DropdownToggleProps extends HTMLAttributes<HTMLElement> {
caret?: boolean;
tag?: ElementType;
color?: string;
inNavbar?: boolean;
/** Classi aggiuntive da usare per il componente Button */
className?: string;
testId?: string;
}

export const DropdownToggle: FC<DropdownToggleProps> = ({
className,
testId,
children,
caret,
tag = 'button',
inNavbar,
color,
...attributes
}) => {
const toggleRef = useRef<HTMLAnchorElement & HTMLButtonElement>(null);

const Tag = tag === 'a' || inNavbar ? 'a' : Button;

useEffect(() => {
if (toggleRef.current) {
new Dropdown(toggleRef.current as HTMLAnchorElement & HTMLButtonElement);
}
});
const classes = classNames(className, {
'btn-dropdown': Tag === 'a' && !inNavbar,
'dropdown-toggle': true,
'nav-link': inNavbar
});
const iconClasses = classNames({
'icon-expand': true,
'icon-sm': !inNavbar,
'icon-xs': inNavbar,
'ms-1': inNavbar,
'icon-light': Tag.valueOf() !== 'a' ? true : false
});
return (
<Tag
role={Tag.valueOf() === 'a' ? 'button' : undefined}
color={color}
ref={toggleRef}
className={classes}
data-bs-toggle='dropdown'
aria-haspopup='true'
data-testid={testId}
{...attributes}
>
{children}
{caret === true ? <Icon icon='it-expand' className={iconClasses} /> : null}
</Tag>
);
};
28 changes: 9 additions & 19 deletions src/Megamenu/MegamenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
import React, { FC, HTMLAttributes, useRef } from 'react';
import { DropdownMenu, DropdownToggle, UncontrolledDropdown } from 'reactstrap';
import React, { FC, HTMLAttributes } from 'react';
import { Dropdown } from '../Dropdown/Dropdown';
import { DropdownMenu } from '../Dropdown/DropdownMenu';
import { DropdownToggle } from '../Dropdown/DropdownToggle';
import classNames from 'classnames';
import { Icon } from '../Icon/Icon';

export interface MegamenuItemProps extends HTMLAttributes<HTMLUListElement> {
/** Etichetta del megamenu visibile all'interno della barra di navigazione */
itemName: string;
/** Classi aggiuntive da usare per il componente UncontrolledDropdown */
/** Classi aggiuntive da usare per il componente Dropdown */
className?: string;
}

export const MegamenuItem: FC<MegamenuItemProps> = ({ itemName, className, children, ...attributes }) => {
const classes = classNames(className, 'megamenu');
const [isOpen, setShowButton] = React.useState(false);
const toggleRef = useRef<DropdownToggle>(null);
const toggleClasses = classNames('px-lg-2', 'px-xl-3', {
show: isOpen
});
const setMegamenuButtonClass = () => {
//setShowButton(contact);
if (toggleRef && toggleRef.current) {
setShowButton(toggleRef.current.context.isOpen);
}
};
const toggleClasses = classNames('px-lg-2', 'px-xl-3');

return (
<UncontrolledDropdown nav tag='li' className={classes} {...attributes} inNavbar onToggle={setMegamenuButtonClass}>
<DropdownToggle caret nav tag='button' className={toggleClasses} ref={toggleRef}>
<Dropdown tag='li' className={classes} {...attributes} inNavbar>
<DropdownToggle caret className={toggleClasses} inNavbar>
<span>{itemName}</span>
<Icon icon='it-expand' size='xs' className='ms-1' />
</DropdownToggle>
<DropdownMenu>
<div className='megamenu pb-5 pt-3 py-lg-0'>{children}</div>
</DropdownMenu>
</UncontrolledDropdown>
</Dropdown>
);
};
19 changes: 6 additions & 13 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,8 @@ export {
NavItem,
NavLink,
BreadcrumbItem,
ButtonDropdown,
ButtonGroup,
ButtonToolbar,
Dropdown,
DropdownItem,
DropdownMenu,
DropdownToggle,
Fade,
CardLink,
CardGroup,
Expand Down Expand Up @@ -47,9 +42,7 @@ export {
ListGroupItemText,
ListGroupItemHeading,
UncontrolledAlert,
UncontrolledButtonDropdown,
UncontrolledCollapse,
UncontrolledDropdown,
UncontrolledTooltip,
Util
} from 'reactstrap';
Expand Down Expand Up @@ -88,6 +81,9 @@ export { CardSignature } from './Card/CardSignature';
export { CardFooterCTA } from './Card/CardFooterCTA';
export { CardReadMore } from './Card/CardReadMore';
export { Collapse } from './Collapse/Collapse';
export { DropdownMenu } from './Dropdown/DropdownMenu';
export { DropdownToggle } from './Dropdown/DropdownToggle';
export { Dropdown } from './Dropdown/Dropdown';
export { GridItem, GridItemText, GridItemTextWrapper, GridList, GridRow } from './Grid/index';
export { Header } from './Header/Header';
export { Headers } from './Header/Headers';
Expand Down Expand Up @@ -176,6 +172,9 @@ export type { CardTagsHeaderProps } from './Card/CardTagsHeader';
export type { CardSignatureProps } from './Card/CardSignature';
export type { CardFooterCTAProps } from './Card/CardFooterCTA';
export type { CardReadMoreProps } from './Card/CardReadMore';
export { DropdownMenuProps } from './Dropdown/DropdownMenu';
export { DropdownToggleProps } from './Dropdown/DropdownToggle';
export { DropdownProps } from './Dropdown/Dropdown';
export type {
GridItemProps,
GridItemTextProps,
Expand Down Expand Up @@ -259,10 +258,6 @@ export type {
ButtonDropdownProps,
ButtonGroupProps,
ButtonToolbarProps,
DropdownProps,
DropdownItemProps,
DropdownMenuProps,
DropdownToggleProps,
FadeProps,
CardLinkProps,
CardGroupProps,
Expand Down Expand Up @@ -295,9 +290,7 @@ export type {
ListGroupItemTextProps,
ListGroupItemHeadingProps,
UncontrolledAlertProps,
UncontrolledButtonDropdownProps,
UncontrolledCollapseProps,
UncontrolledDropdownProps,
UncontrolledTooltipProps
} from 'reactstrap';
export type { useNavScrollArgs, useNavScrollResult, RegisterOptions, ChangesType } from 'react-use-navscroll';
30 changes: 7 additions & 23 deletions stories/Avatar/AvatarGroupsOverlapping.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
AvatarGroupContainer,
Icon,
LinkListItem,
UncontrolledDropdown,
Dropdown,
LinkList,
DropdownMenu,
DropdownToggle
Expand Down Expand Up @@ -65,16 +65,8 @@ export const SmallOverlappingAvatars = () => {
</li>
<li>
<AvatarIcon size='sm' color='dropdown'>
<UncontrolledDropdown>
<DropdownToggle
className={`btn btn-dropdown dropdown-toggle`}
href='#'
tag='button'
id='dropdownMenuLink'
data-toggle='dropdown'
aria-haspopup
aria-expanded='false'
>
<Dropdown>
<DropdownToggle id='dropdownMenuLink'>
<span className='visually-hidden'>Visualizza altri 4 utenti</span>
<span aria-hidden='true'>+4</span>
</DropdownToggle>
Expand Down Expand Up @@ -106,7 +98,7 @@ export const SmallOverlappingAvatars = () => {
</LinkListItem>
</LinkList>
</DropdownMenu>
</UncontrolledDropdown>
</Dropdown>
</AvatarIcon>
</li>
</AvatarGroupContainer>
Expand Down Expand Up @@ -145,16 +137,8 @@ export const MediumOverlaidAvatars = () => {
</li>
<li>
<AvatarIcon size='md' color='dropdown'>
<UncontrolledDropdown>
<DropdownToggle
className={`btn btn-dropdown dropdown-toggle`}
href='#'
tag='button'
id='dropdownMenuLink2'
data-toggle='dropdown'
aria-haspopup
aria-expanded='false'
>
<Dropdown>
<DropdownToggle id='dropdownMenuLink2'>
<span className='visually-hidden'>Visualizza altri 4 utenti</span>
<span aria-hidden='true'>+4</span>
</DropdownToggle>
Expand Down Expand Up @@ -186,7 +170,7 @@ export const MediumOverlaidAvatars = () => {
</LinkListItem>
</LinkList>
</DropdownMenu>
</UncontrolledDropdown>
</Dropdown>
</AvatarIcon>
</li>
</AvatarGroupContainer>
Expand Down
Loading

0 comments on commit 6a02102

Please sign in to comment.