generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(header): implementation in preparation for Volto integration #…
- Loading branch information
Showing
101 changed files
with
2,609 additions
and
1,606 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,2 @@ | ||
export useClickOutside from './useClickOutside'; | ||
export usePrevious from './usePrevious'; |
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,30 @@ | ||
import React from 'react'; | ||
import { doesNodeContainClick } from 'semantic-ui-react/dist/commonjs/lib'; | ||
|
||
/** | ||
* Call the callback when a click happens outside the targetRefs elements | ||
*/ | ||
export default function useClickOutside({ targetRefs = [], callback }) { | ||
const handleClickOutside = React.useCallback( | ||
(e) => { | ||
const isInsideTarget = | ||
targetRefs.findIndex( | ||
(nodeRef) => | ||
nodeRef.current && doesNodeContainClick(nodeRef.current, e), | ||
) > -1; | ||
|
||
if (isInsideTarget) return; | ||
callback(); | ||
}, | ||
[callback, targetRefs], | ||
); | ||
|
||
React.useLayoutEffect(() => { | ||
document.addEventListener('mousedown', handleClickOutside, false); | ||
return () => { | ||
document.removeEventListener('mousedown', handleClickOutside, false); | ||
}; | ||
}, [handleClickOutside]); | ||
|
||
return null; | ||
} |
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,9 @@ | ||
import React from 'react'; | ||
|
||
export default function usePrevious(value) { | ||
const ref = React.useRef(); | ||
React.useEffect(() => { | ||
ref.current = value; | ||
}); | ||
return ref.current; | ||
} |
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,32 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
Avatar.propTypes = { | ||
title: PropTypes.string, | ||
info: PropTypes.string, | ||
}; | ||
|
||
function Avatar({ image_url, children, ...rest }) { | ||
return ( | ||
<div className={`eea avatar ${rest.avatarSize}`} {...rest}> | ||
<div className="wrapper"> | ||
<div className="image-wrapper"> | ||
<div | ||
className="image" | ||
style={{ backgroundImage: `url(${image_url})` }} | ||
></div> | ||
</div> | ||
<div className="content-wrapper">{children}</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
Avatar.Content = ({ children }) => { | ||
return <div className="content">{children}</div>; | ||
}; | ||
|
||
Avatar.Title = ({ children }) => <p className="title">{children}</p>; | ||
Avatar.Metadata = ({ children }) => <p className="metadata">{children}</p>; | ||
|
||
export default Avatar; |
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,61 @@ | ||
import React from 'react'; | ||
import Avatar from './Avatar'; | ||
// eslint-disable-next-line import/no-unresolved | ||
import imgUrl from '@eeacms/volto-eea-design-system/../theme/themes/eea/assets/images/avatar.png'; | ||
|
||
export default { | ||
title: 'Components/Avatar', | ||
component: Avatar, | ||
argTypes: { | ||
title: { | ||
description: 'avatar title', | ||
table: { | ||
defaultValue: { summary: '""' }, | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
info: { | ||
description: 'avatar secondary info', | ||
table: { | ||
defaultValue: { summary: '""' }, | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
image: { | ||
description: 'avatar image', | ||
table: { | ||
defaultValue: { summary: '""' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const DefaultTemplate = (args) => ( | ||
<Avatar avatarSize="big" {...args} image_url={imgUrl}> | ||
<Avatar.Content> | ||
<Avatar.Title>{args.title}</Avatar.Title> | ||
<Avatar.Metadata>{args.info}</Avatar.Metadata> | ||
</Avatar.Content> | ||
</Avatar> | ||
); | ||
|
||
export const Default = DefaultTemplate.bind({}); | ||
Default.args = { | ||
title: 'Lorem ipsum', | ||
info: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
}; | ||
|
||
const SmallTemplate = (args) => ( | ||
<Avatar avatarSize="small" {...args} image_url={imgUrl}> | ||
<Avatar.Content> | ||
<Avatar.Title>{args.title}</Avatar.Title> | ||
<Avatar.Metadata>{args.info}</Avatar.Metadata> | ||
</Avatar.Content> | ||
</Avatar> | ||
); | ||
|
||
export const Small = SmallTemplate.bind({}); | ||
Small.args = { | ||
title: 'Lorem ipsum', | ||
info: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', | ||
}; |
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,49 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import Avatar from '../Avatar/Avatar'; | ||
import { Grid } from 'semantic-ui-react'; | ||
|
||
AvatarGrid.propTypes = { | ||
title: PropTypes.string, | ||
}; | ||
|
||
function AvatarGrid({ children, ...rest }) { | ||
return ( | ||
<div className="eea avatar-grid" {...rest}> | ||
<div className="wrapper">{children}</div> | ||
</div> | ||
); | ||
} | ||
|
||
AvatarGrid.Content = ({ children }) => { | ||
return <div className="content">{children}</div>; | ||
}; | ||
|
||
AvatarGrid.Title = ({ children, ...rest }) => ( | ||
<p className={`grid-title ${rest.showTitle ? '' : 'hidden'}`}>{children}</p> | ||
); | ||
AvatarGrid.Group = ({ children, ...rest }) => { | ||
let avatars = rest.avatars; | ||
if (rest.avatars.length > 3) { | ||
avatars = avatars.slice(0, 3); | ||
} | ||
return ( | ||
<div className="avatar group"> | ||
<Grid> | ||
{avatars.map((avatar) => ( | ||
<Grid.Column mobile={12} tablet={4} computer={4}> | ||
<div className="avatar-wrapper"> | ||
<Avatar {...rest} image_url={avatar.image_url} avatarSize="big"> | ||
<Avatar.Content> | ||
<Avatar.Title>{avatar.title}</Avatar.Title> | ||
<Avatar.Metadata>{avatar.metadata}</Avatar.Metadata> | ||
</Avatar.Content> | ||
</Avatar> | ||
</div> | ||
</Grid.Column> | ||
))} | ||
</Grid> | ||
</div> | ||
); | ||
}; | ||
export default AvatarGrid; |
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'; | ||
// eslint-disable-next-line import/no-unresolved | ||
import imgUrl from '@eeacms/volto-eea-design-system/../theme/themes/eea/assets/images/avatar.png'; | ||
import AvatarGrid from './AvatarGrid'; | ||
|
||
export default { | ||
title: 'Components/Avatar Grid', | ||
component: AvatarGrid, | ||
argTypes: { | ||
showTitle: { | ||
description: 'show / hide title', | ||
table: { | ||
type: { summary: 'boolean' }, | ||
defaultValue: { summary: true }, | ||
}, | ||
}, | ||
title: { | ||
description: 'avatar grid title', | ||
table: { | ||
defaultValue: { summary: '""' }, | ||
type: { summary: 'string' }, | ||
}, | ||
}, | ||
avatars: { | ||
description: 'avatar data', | ||
table: { | ||
type: { summary: 'Object' }, | ||
defaultValue: { summary: ' "" ' }, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const GridTemplate = (args) => ( | ||
<AvatarGrid> | ||
<AvatarGrid.Content> | ||
<AvatarGrid.Title showTitle={args.showTitle}> | ||
{args.title} | ||
</AvatarGrid.Title> | ||
<AvatarGrid.Group avatars={args.avatars}></AvatarGrid.Group> | ||
</AvatarGrid.Content> | ||
</AvatarGrid> | ||
); | ||
|
||
export const Default = GridTemplate.bind({}); | ||
Default.args = { | ||
title: 'Amet - Lorem ipsum dolor sit amet', | ||
showTitle: true, | ||
avatars: [ | ||
{ | ||
image_url: imgUrl, | ||
title: 'Lorem ipsum', | ||
metadata: 'Urna auctor pharetra aenean sed gravida quam', | ||
}, | ||
{ | ||
image_url: imgUrl, | ||
title: 'Lorem ipsum', | ||
metadata: 'Duis vel eu placerat proin diam id enim suspendisse erat', | ||
}, | ||
{ | ||
image_url: imgUrl, | ||
title: 'Lorem ipsum', | ||
metadata: 'Egetisi gravida pellentesque volutpat diamon', | ||
}, | ||
], | ||
}; |
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,7 @@ | ||
import React from 'react'; | ||
|
||
function Divider({ ...rest }) { | ||
return <div className="eea divider" {...rest}></div>; | ||
} | ||
|
||
export default Divider; |
Oops, something went wrong.