-
Notifications
You must be signed in to change notification settings - Fork 22
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
14 changed files
with
403 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
Share, ShareButton, | ||
} from '@dataesr/react-dsfr'; | ||
|
||
const ShareExampla = () => { | ||
const onClickFacebook = () => { | ||
window.open( | ||
'https://www.facebook.com/sharer.php', | ||
'Partager sur Facebook', | ||
'toolbar=no,location=yes,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450', | ||
); | ||
}; | ||
|
||
const onClickTwitter = () => { | ||
window.open( | ||
'https://twitter.com/intent/tweet', | ||
'Partager sur Twitter', | ||
'toolbar=no,location=yes,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=420', | ||
); | ||
}; | ||
|
||
const onClickLinkedin = () => { | ||
window.open( | ||
'https://www.linkedin.com/shareArticle', | ||
'Partager sur Linkedin', | ||
'toolbar=no,location=yes,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=420', | ||
); | ||
}; | ||
|
||
const onCopy = () => { | ||
navigator.clipboard.writeText(window.location); | ||
}; | ||
|
||
return ( | ||
<Share title="Partager la page"> | ||
<ShareButton | ||
onClick={onClickFacebook} | ||
type="facebook" | ||
label="Partager sur facebook" | ||
href="https://www.facebook.com/sharer.php" | ||
/> | ||
<ShareButton | ||
onClick={onClickTwitter} | ||
type="twitter" | ||
label="Partager sur twitter" | ||
href="https://twitter.com/intent/tweet" | ||
/> | ||
<ShareButton | ||
onClick={onClickLinkedin} | ||
type="linkedin" | ||
label="Partager sur linkedin" | ||
href="https://www.linkedin.com/shareArticle" | ||
/> | ||
<ShareButton | ||
type="mail" | ||
label="Partager par email" | ||
href="mailto:?subject=[À MODIFIER - objet du mail]&body=[À MODIFIER - titre ou texte descriptif de la page] [À MODIFIER - url de la page]" | ||
/> | ||
<ShareButton type="copy" label={'Copier l\'adresse'} onClick={onCopy} /> | ||
</Share> | ||
); | ||
}; | ||
|
||
export default ShareExampla; |
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,16 @@ | ||
import * as React from 'react'; | ||
|
||
export type ShareChildren = React.ReactNode[] | React.ReactNode; | ||
|
||
export type ShareClassName = string | Object | any[]; | ||
|
||
export interface ShareProps { | ||
title: string; | ||
children: ShareChildren; | ||
className?: ShareClassName; | ||
} | ||
|
||
declare const Share: React.FC<ShareProps>; | ||
|
||
export default Share; | ||
|
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,44 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import dataAttributes from '../../../utils/data-attributes'; | ||
|
||
/* | ||
* DSFR v1.5.0 | ||
*/ | ||
import '@gouvfr/dsfr/dist/component/share/share.css'; | ||
|
||
const Share = ({ | ||
children, className, title, ...remainingProps | ||
}) => { | ||
const _className = classNames('fr-share', className); | ||
|
||
return ( | ||
<div | ||
className={_className} | ||
{...dataAttributes.getAll(remainingProps)} | ||
> | ||
<p className="fr-share__title">{title}</p> | ||
<ul className="fr-btns-group"> | ||
{children} | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
Share.defaultProps = { | ||
className: '', | ||
title: '', | ||
}; | ||
|
||
Share.propTypes = { | ||
children: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired, | ||
title: PropTypes.string, | ||
className: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.object, | ||
PropTypes.array, | ||
]), | ||
}; | ||
|
||
export default Share; |
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,16 @@ | ||
# Méta données | ||
cf [Confluences](https://gouvfr.atlassian.net/wiki/spaces/DB/pages/771555355/Partage+-+Share) | ||
<!-- Balises meta Open Graph --> | ||
<meta property="og:title" content="[À MODIFIER | Système de Design de l'État]"> | ||
<meta property="og:description" content="[À MODIFIER | Développer vos sites et applications en utilisant des composants prêts à l'emploi, accessibles et ergonomiques]"> | ||
<meta property="og:image" content="[À MODIFIER | https://systeme-de-design.gouv.fr/src/img/systeme-de-design.gouv.fr.jpg]"> | ||
<meta property="og:type" content="website"> | ||
<meta property="og:url" content="[À MODIFIER | https://systeme-de-design.gouv.fr/]"> | ||
<meta property="og:site_name" content="[À MODIFIER | Site officiel du Système de Design de l'État]"> | ||
<meta property="og:image:alt" content="[À MODIFIER | République Française - Système de Design de l'État]"> | ||
|
||
<!-- Balise méta pour twitter --> | ||
<meta name="twitter:card" content="summary_large_image"> | ||
<meta name="twitter:site" content="[À MODIFIER | @usernameTwitter]"> | ||
<meta name="twitter:image:alt" content="[À MODIFIER | République Française - Système de Design de l'État]"> | ||
|
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,16 @@ | ||
import * as React from 'react'; | ||
|
||
export type ShareButtonClassName = string | Object | any[]; | ||
|
||
export interface ShareButtonProps { | ||
type: string; | ||
label: string; | ||
href?: string; | ||
onClick?: (...args: any[]) => any; | ||
className?: ShareButtonClassName; | ||
} | ||
|
||
declare const ShareButton: React.FC<ShareButtonProps>; | ||
|
||
export default ShareButton; | ||
|
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,85 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import dataAttributes from '../../../utils/data-attributes'; | ||
|
||
/* | ||
* DSFR v1.5.0 | ||
*/ | ||
import '@gouvfr/dsfr/dist/component/share/share.css'; | ||
|
||
const ShareButton = ({ | ||
label, href, className, type, onClick, ...remainingProps | ||
}) => { | ||
const _className = classNames('fr-share', className); | ||
|
||
const _onClick = (e) => { | ||
e.preventDefault(); | ||
onClick(e); | ||
}; | ||
|
||
const renderLink = () => { | ||
let link = ( | ||
<a | ||
className={`fr-btn fr-btn--${type}`} | ||
onClick={_onClick} | ||
href={href} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{label} | ||
</a> | ||
); | ||
|
||
if (type === 'mail') { | ||
link = ( | ||
<a | ||
className={`fr-btn fr-btn--${type}`} | ||
href={href} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{label} | ||
</a> | ||
); | ||
} | ||
|
||
return link; | ||
}; | ||
|
||
return ( | ||
<li className={_className} {...dataAttributes.getAll(remainingProps)}> | ||
{type === 'copy' ? ( | ||
<button | ||
type="button" | ||
className="fr-btn--copy fr-btn" | ||
onClick={_onClick} | ||
> | ||
{label} | ||
</button> | ||
) : ( | ||
renderLink() | ||
)} | ||
</li> | ||
); | ||
}; | ||
|
||
ShareButton.defaultProps = { | ||
className: '', | ||
href: '', | ||
onClick: undefined, | ||
}; | ||
|
||
ShareButton.propTypes = { | ||
href: PropTypes.string, | ||
label: PropTypes.string.isRequired, | ||
onClick: PropTypes.func, | ||
type: PropTypes.oneOf(['facebook', 'twitter', 'linkedin', 'copy', 'mail']).isRequired, | ||
className: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.object, | ||
PropTypes.array, | ||
]), | ||
}; | ||
|
||
export default ShareButton; |
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,54 @@ | ||
import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; | ||
|
||
import Enzyme, { shallow } from 'enzyme'; | ||
import renderer from 'react-test-renderer'; | ||
import React from 'react'; | ||
import { Share, ShareButton } from '..'; | ||
|
||
Enzyme.configure({ adapter: new Adapter() }); | ||
|
||
jest.mock('uuid', () => ({ | ||
v4: jest.fn(), | ||
})); | ||
|
||
describe('<Share />', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = (props = {}) => shallow( | ||
<ShareButton | ||
onClick={props.onClick} | ||
type="facebook" | ||
label="Partager sur facebook" | ||
href="https://www.facebook.com/sharer.php" | ||
/>, | ||
); | ||
}); | ||
|
||
it('should render Share properly', () => { | ||
const component = renderer | ||
.create( | ||
<Share title="Partager la page"> | ||
<ShareButton | ||
onClick={() => {}} | ||
type="facebook" | ||
label="Partager sur facebook" | ||
href="https://www.facebook.com/sharer.php" | ||
/> | ||
</Share>, | ||
) | ||
.toJSON(); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
test('onClick Share facebook', () => { | ||
const mockClick = jest.fn(); | ||
const props = { | ||
onClick: mockClick, | ||
}; | ||
|
||
const component = wrapper({ ...props }); | ||
component.find('.fr-btn--facebook').simulate('click', { preventDefault: () => {} }); | ||
expect(mockClick).toHaveBeenCalled(); | ||
}); | ||
}); |
Oops, something went wrong.