-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
193 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.