-
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
8 changed files
with
3,652 additions
and
1,672 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import classNames from 'classnames'; | ||
import React, { ElementType, FC, HTMLAttributes } from 'react'; | ||
|
||
export interface ListProps extends HTMLAttributes<HTMLUListElement> { | ||
/** Classi aggiuntive da usare per il componente lista del List */ | ||
className?: string; | ||
/** Classi aggiuntive da usare per il componente wrapper del List */ | ||
wrapperClassName?: string; | ||
/** | ||
* Utilizzarlo in caso di utilizzo di componenti personalizzati per il wrapper della lista. | ||
* Nota: viene ignorato quando usato in lista annidate. | ||
* */ | ||
tag?: ElementType; | ||
/** Quando attivo rimuove il componente contenitore della ListList. Utile per alcuni tipi di liste annidate. */ | ||
noWrapper?: boolean; | ||
testId?: string; | ||
} | ||
|
||
export const List: FC<ListProps> = ({ | ||
className, | ||
wrapperClassName, | ||
tag = 'div', | ||
noWrapper, | ||
testId, | ||
...attributes | ||
}) => { | ||
const Tag = tag; | ||
const wrapperClasses = classNames('it-list-wrapper', wrapperClassName); | ||
const classes = classNames(className, 'it-list'); | ||
|
||
if (noWrapper) { | ||
return <ul {...attributes} className={classes} data-testid={testId} />; | ||
} | ||
|
||
return ( | ||
<Tag className={wrapperClasses} data-testid={testId}> | ||
<ul {...attributes} className={classes} /> | ||
</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,86 @@ | ||
import classNames from 'classnames'; | ||
import React, { AnchorHTMLAttributes, ElementType, FC, ReactNode } from 'react'; | ||
|
||
export interface ListItemProps extends AnchorHTMLAttributes<HTMLAnchorElement> { | ||
/** Indica se l'elemento è attivo o no */ | ||
active?: boolean; | ||
/** Indica se l'elemento ha un avatar */ | ||
avatar?: ReactNode; | ||
/** Indica se l'elemento ha una icona */ | ||
icon?: ReactNode; | ||
/** Indica se l'elemento ha una immagine */ | ||
img?: ReactNode; | ||
/** Utilizzarlo in caso di utilizzo di componenti personalizzati */ | ||
tag?: ElementType; | ||
/** Classi aggiuntive da usare per il componente ListItem */ | ||
className?: string; | ||
/** Classi aggiuntive da usare per l'elemento contenitore dell'item */ | ||
wrapperClassName?: string; | ||
/** Indica il link a cui l'elemento deve puntare. */ | ||
href?: string; | ||
/** Indica il link route a cui l'elemento deve puntare. */ | ||
to?: string; | ||
testId?: string; | ||
} | ||
|
||
export const ListItem: FC<ListItemProps> & { | ||
MultipleAction: typeof MultipleAction; | ||
} = ({ | ||
className, | ||
active, | ||
avatar, | ||
icon, | ||
img, | ||
href, | ||
tag = 'div', | ||
to, | ||
wrapperClassName, | ||
testId, | ||
children, | ||
...attributes | ||
}) => { | ||
let Tag = tag; | ||
const classes = classNames( | ||
className, | ||
{ active }, | ||
'list-item' | ||
), | ||
classesItem = classNames(className, { | ||
'it-rounded-icon': icon, | ||
'avatar size-lg': avatar, | ||
'it-thumb': img | ||
}), | ||
leftItem = icon || avatar || img; | ||
|
||
if (href) { | ||
return ( | ||
<li className={wrapperClassName} data-testid={testId}> | ||
<Tag> | ||
<a href={href || '#'} {...attributes} className={classes}> | ||
{children} | ||
</a> | ||
</Tag> | ||
</li> | ||
); | ||
} | ||
|
||
return ( | ||
<li className={wrapperClassName} data-testid={testId}> | ||
<Tag | ||
{...attributes} | ||
className={classes} | ||
href={href} | ||
to={to} | ||
> | ||
{leftItem && <div className={classesItem}>{leftItem}</div>} | ||
<div className="it-right-zone">{children}</div> | ||
</Tag> | ||
</li> | ||
); | ||
}; | ||
|
||
const MultipleAction: FC<ListItemProps> = ({ children }) => { | ||
return <span className='it-multiple'>{children}</span> | ||
}; | ||
|
||
ListItem.MultipleAction = MultipleAction; |
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.