Skip to content

Commit

Permalink
feat(Sidebar): mobile support added
Browse files Browse the repository at this point in the history
  • Loading branch information
Utzel-Butzel committed Feb 8, 2021
1 parent bdfefbf commit ae21bcf
Show file tree
Hide file tree
Showing 14 changed files with 1,383 additions and 312 deletions.
867 changes: 867 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions src/components/Item/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export const Item = ({
children,
className,
href,
subText,
icon,
subContent,
image,
hint,
noImage,
showAdditionalIcon,
title,
kind = 'large',
Expand All @@ -32,7 +33,14 @@ export const Item = ({
);
return (
<div className={classNames} {...other}>
<div className={`${prefix}--item__icon`}>{icon}</div>
{image ? (
<div className={`${prefix}--item__image`}>{image}</div>
) : noImage ? (
<div className={`${prefix}--item__image ${prefix}--item__image-empty`}>
Empty
</div>
) : null}

<div className={`${prefix}--item__content`}>
{title && (
<div className={`${prefix}--item__title-wrapper`}>
Expand All @@ -55,8 +63,8 @@ export const Item = ({
{children && (
<div className={`${prefix}--item__text`}>{children}</div>
)}
{subText && (
<div className={`${prefix}--item__subtext`}>{subText}</div>
{subContent && (
<div className={`${prefix}--item__subContent`}>{subContent}</div>
)}
</div>
<div className={`${prefix}--item__right`}>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Item/Item.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const Regular = (args) => <Item {...args} />;
Regular.args = {
title: 'A title is shown',
children: `nonumy eirmod tempor invidunt`,
subText: `This is the subText. Lorem ipsum dolor sit amet, consetetur sadipscing elitr. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. `,
subContent: `This is the subContent. Lorem ipsum dolor sit amet, consetetur sadipscing elitr. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. `,
icon: (
<img
alt="Moving van"
Expand All @@ -37,7 +37,7 @@ export const Horizontal = (args) => <Item {...args} />;
Horizontal.args = {
title: 'A title is shown',
children: `nonumy eirmod tempor invidunt`,
subText: `This is the subText. Lorem ipsum dolor sit amet, consetetur sadipscing elitr. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. `,
subContent: `This is the subContent. Lorem ipsum dolor sit amet, consetetur sadipscing elitr. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. `,
kind: 'horizontal',
icon: (
<img
Expand Down
10 changes: 5 additions & 5 deletions src/components/Item/_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
.#{$prefix}--item__text-wrapper {
flex-direction: column;
}
.#{$prefix}--item__icon {
.#{$prefix}--item__image {
width: 9em;
margin-bottom: 1em;
}
Expand All @@ -52,6 +52,7 @@
}

&--sidebar {
cursor: pointer;
border-bottom: 1px solid var(--ui-03);
}
&--button {
Expand All @@ -62,7 +63,6 @@
}
&--horizontal {
padding: 1em;
height: 100%;
width: 100%;
flex-direction: row;

Expand All @@ -75,7 +75,7 @@
.#{$prefix}--item__title-wrapper {
justify-content: space-between;
}
.#{$prefix}--item__icon {
.#{$prefix}--item__image {
width: 5rem;
margin-right: 1em;
}
Expand Down Expand Up @@ -105,7 +105,7 @@
color: var(--text-02);
margin-left: 1em;
}
.#{$prefix}--item__additional-icon {
.#{$prefix}--item__additional-image {
font-weight: normal;
height: 0.6em;
width: auto;
Expand Down Expand Up @@ -142,7 +142,7 @@
}
}

.#{$prefix}--item__icon {
.#{$prefix}--item__image {
svg,
.svg-inline--fa,
img {
Expand Down

Large diffs are not rendered by default.

File renamed without changes.
49 changes: 49 additions & 0 deletions src/components/SidebarContent/Sidebar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import PropTypes from 'prop-types';
import SidebarItem from '../SidebarItem/SidebarItem';
import Icon from '../Icon';
import { iconChevronLeft } from '@wfp/icons';

function Sidebar({
//data,
active,
children,
sidebarMobileHeader,
sidebarMobileHeaderLink,
sidebarContent,
//updateContent,
//enableSearch,
...other
}) {
return (
<div
className={`wfp--sidebar-content__container wfp--sidebar-content__container-${
active ? 'active' : ''
}`}
{...other}>
<div className="wfp--sidebar-item-content">{sidebarContent}</div>
<div className="wfp--content-section">
<div className="wfp--sidebar-content-mobile-header">
{sidebarMobileHeader}
</div>

{children}
</div>
</div>
);
}

export default Sidebar;

export function SidebarHeader({ children }) {
return <div className="wfp--sidebar-content__header">{children}</div>;
}

export function SidebarBackButton({ children, ...other }) {
return (
<div className="wfp--sidebar-content__back-button" {...other}>
<Icon icon={iconChevronLeft} />
{children}
</div>
);
}
174 changes: 174 additions & 0 deletions src/components/SidebarContent/SidebarContent.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import React, { useState } from 'react';

import markdown from './README.mdx';
import Sidebar from './Sidebar';
import { SidebarHeader, SidebarBackButton } from './Sidebar';
import DATA from './PHONEBOOK.json';
import User from '../User';
import { List, ListItem } from '../List';
import MainNavigation from '../MainNavigation';
import Item from '../Item';
import Empty from '../Empty';
import Search from '../Search';

export default {
title: 'Templates/SidebarContent',
parameters: {
status: 'released',
mdx: markdown,
previewWidth: 'full',
},
};

export const Phonebook = (args) => {
const [selectedUserId, setSelectedUserId] = useState(null);
const [search, setSearch] = useState(null);
const selectedUserData = DATA.find((e) => e.id === selectedUserId);

const searchResults = search
? DATA.filter((e) =>
e.full_name.toLocaleLowerCase().includes(search.toLocaleLowerCase())
)
: DATA;

return (
<>
<MainNavigation pageWidth="full" />
<Sidebar
active={selectedUserId}
sidebarMobileHeader={
<>
<SidebarBackButton onClick={() => setSelectedUserId()}>
Back
</SidebarBackButton>
<div>Detail page</div>
</>
}
sidebarContent={
<>
<SidebarHeader>
<Search
placeHolderText="Type to search user"
onChange={(e) => setSearch(e)}
/>
</SidebarHeader>
{searchResults && searchResults.length > 0 ? (
searchResults.map((user, key) => (
<Item
key={key}
image={
user.profile_image ? (
<img alt={user.full_name} src={user.profile_image} />
) : undefined
}
title={user.full_name}
children={user.email}
subContent={user.phone_number}
kind="horizontal"
wrapper="sidebar"
onClick={() => setSelectedUserId(user.id)}
noImage
/>
))
) : (
<Empty title="No results">Please check your search</Empty>
)}
</>
}>
{selectedUserData ? (
<div
style={{
backgroundColor: '#fff',
overflow: 'scroll',
padding: '1rem',
height: '100vh',
}}>
<User
id={selectedUserData.staff_id}
alt="avatar"
description={
<List small>
<ListItem>{selectedUserData.job_title}</ListItem>
</List>
}
image={selectedUserData.profile_image}
name={selectedUserData.full_name}
style={{
borderBottom: '1px solid #edf1f3',
padding: '1rem 0 2rem 0',
marginBottom: '1rem',
}}
/>
<div>
<div
style={{
borderBottom: '1px solid #edf1f3',
padding: '1rem 0',
}}>
<h4>Bio</h4>
<List small>
<ListItem>{selectedUserData.bio}</ListItem>
</List>
</div>

<div
style={{
borderBottom: '1px solid #edf1f3',
padding: '1rem 0',
}}>
<h4>Contact</h4>
<List small>
<ListItem>email: {selectedUserData.email}</ListItem>
<ListItem>phone: {selectedUserData.phone_number}</ListItem>
</List>
</div>

<div style={{ padding: '1rem 0' }}>
<h4>Location</h4>
<List small>
<ListItem>country: {selectedUserData.country}</ListItem>
</List>
</div>
</div>
</div>
) : (
<Empty title="No user selected">Please select a user</Empty>
)}
</Sidebar>
</>
);
};
/*
export const Regular = (args) => {
const sidebarSchema = {
title: 'full_name',
content: 'email',
subContent: 'phone_number',
};
const content = (
<div style={{ padding: '1rem' }}>
<div>
<Text kind="title">Report preview year 2020</Text>
</div>
<Item
additionalInfo="Friday, 21.02.20"
content="409 boys, 422 girls"
hintInfo={<Tag type="warning">not synced</Tag>}
noImage
subContent="meal served"
title="831 students"
/>
</div>
);
return (
<>
<MainNavigation />
<Sidebar
data={DATA}
sidebarItemSchema={sidebarSchema}
content={content}
/>
</>
);
};*/
Loading

0 comments on commit ae21bcf

Please sign in to comment.