-
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
4 changed files
with
71 additions
and
2 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,35 @@ | ||
import React, { ReactChild } from 'react'; | ||
import { Icon } from '../Icon/Icon'; | ||
import classNames from 'classnames'; | ||
import { Button } from '../Button/Button'; | ||
|
||
export interface GoBackProps { | ||
/** | ||
* Optional classnames to pass to the element | ||
*/ | ||
className?: string; | ||
/** | ||
* Render the link variant of the go back button | ||
*/ | ||
link?: boolean; | ||
/** | ||
* Render the up variant of the go back button | ||
*/ | ||
up?: boolean; | ||
children: ReactChild; | ||
} | ||
|
||
const goBack = () => { | ||
window.history.back(); | ||
}; | ||
|
||
export const GoBack = ({ className, link = false, up = false, children }: GoBackProps) => { | ||
const Tag = link ? 'a' : Button; | ||
|
||
return ( | ||
<Tag className={classNames(className, 'go-back')} color='primary' onClick={goBack}> | ||
<Icon color={link ? 'primary' : 'white'} icon={up ? 'it-arrow-up' : 'it-arrow-left'} /> | ||
{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
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,33 @@ | ||
import { Meta, Canvas } from '@storybook/addon-docs'; | ||
import { GoBack } from '../../src'; | ||
|
||
<Meta title='Documentazione/Menu di navigazione/Torna Indietro' /> | ||
|
||
# Torna indietro | ||
|
||
## Esempio link | ||
|
||
Per visualizzare il Back to top nella posizione corretta è necessario scrollare questa pagina. L'esempio del codice | ||
sottostante sarà visibile solo a scroll avvenuto. | ||
|
||
<Canvas> | ||
<GoBack link>Torna indietro</GoBack> | ||
</Canvas> | ||
|
||
### Pulsanti | ||
|
||
Aggiungendo la prop `up` si ottiene l'icona che punta in alto. | ||
|
||
<Canvas> | ||
<GoBack>Torna indietro</GoBack> | ||
<GoBack up>Livello superiore</GoBack> | ||
</Canvas> | ||
|
||
### Pulsanti con sola icona | ||
|
||
Non specificando il testo, il pulsante rimane con sola icona. | ||
|
||
<Canvas> | ||
<GoBack /> | ||
<GoBack up /> | ||
</Canvas> |