feat(Filter/Filters): add emptystate

This commit is contained in:
Aminejv 2022-01-06 18:17:13 +01:00
parent f8cea1f2d5
commit b5b67b94ff

View File

@ -15,8 +15,8 @@ import { css } from "@emotion/react";
import { useFilterContext } from "~/components/core/Filter/Provider"; import { useFilterContext } from "~/components/core/Filter/Provider";
import { Link } from "~/components/core/Link"; import { Link } from "~/components/core/Link";
import { ButtonPrimary, ButtonSecondary } from "~/components/system/components/Buttons"; import { ButtonPrimary, ButtonSecondary } from "~/components/system/components/Buttons";
import { motion } from "framer-motion";
import { FocusRing } from "../FocusRing"; import { FocusRing } from "../FocusRing";
import { Show } from "~/components/utility/Show";
/* ------------------------------------------------------------------------------------------------- /* -------------------------------------------------------------------------------------------------
* Shared components between filters * Shared components between filters
@ -77,7 +77,7 @@ const FilterButton = React.forwardRef(({ children, Icon, image, isSelected, ...p
</Link> </Link>
)); ));
const FilterSection = React.forwardRef(({ title, children, ...props }, ref) => { const FilterSection = React.forwardRef(({ title, children, emptyState, ...props }, ref) => {
const [isExpanded, setExpanded] = React.useState(true); const [isExpanded, setExpanded] = React.useState(true);
const toggleExpandState = () => setExpanded((prev) => !prev); const toggleExpandState = () => setExpanded((prev) => !prev);
@ -89,7 +89,7 @@ const FilterSection = React.forwardRef(({ title, children, ...props }, ref) => {
<Tooltip.Trigger aria-describedby={titleButtonId} aria-expanded={isExpanded}> <Tooltip.Trigger aria-describedby={titleButtonId} aria-expanded={isExpanded}>
<FocusRing> <FocusRing>
<Typography.H6 <Typography.H6
as={motion.button} as="button"
layoutId={title + "title"} layoutId={title + "title"}
css={STYLES_FILTER_TITLE_BUTTON} css={STYLES_FILTER_TITLE_BUTTON}
style={{ paddingLeft: 8, marginBottom: 4 }} style={{ paddingLeft: 8, marginBottom: 4 }}
@ -108,25 +108,26 @@ const FilterSection = React.forwardRef(({ title, children, ...props }, ref) => {
</Tooltip.Root> </Tooltip.Root>
)} )}
{isExpanded ? ( {isExpanded ? (
Array.isArray(children) && children?.length === 0 ? (
<Show when={emptyState}>
<System.P2 color="textGrayDark" style={{ paddingLeft: "8px" }}>
{emptyState}
</System.P2>
</Show>
) : (
<RovingTabIndex.Provider axis="vertical"> <RovingTabIndex.Provider axis="vertical">
<RovingTabIndex.List> <RovingTabIndex.List>
<motion.ul <ul css={STYLES_FILTERS_GROUP}>{children}</ul>
layoutId={title + "section"}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
css={STYLES_FILTERS_GROUP}
>
{children}
</motion.ul>
</RovingTabIndex.List> </RovingTabIndex.List>
</RovingTabIndex.Provider> </RovingTabIndex.Provider>
)
) : null} ) : null}
</div> </div>
); );
}); });
/* ------------------------------------------------------------------------------------------------- /* -------------------------------------------------------------------------------------------------
* InitialFilters * Library
* -----------------------------------------------------------------------------------------------*/ * -----------------------------------------------------------------------------------------------*/
function Library({ page, onAction }) { function Library({ page, onAction }) {
@ -151,11 +152,19 @@ function Library({ page, onAction }) {
); );
} }
/* -------------------------------------------------------------------------------------------------
* Tags
* -----------------------------------------------------------------------------------------------*/
function Tags({ viewer, data, onAction, ...props }) { function Tags({ viewer, data, onAction, ...props }) {
const [, { hidePopup }] = useFilterContext(); const [, { hidePopup }] = useFilterContext();
return ( return (
<FilterSection title="Tags" {...props}> <FilterSection
title="Tags"
emptyState="when you tag a file, that tag will automatically show up here"
{...props}
>
{viewer.slates.map((slate, index) => ( {viewer.slates.map((slate, index) => (
<li key={slate.id}> <li key={slate.id}>
<RovingTabIndex.Item index={index}> <RovingTabIndex.Item index={index}>
@ -175,13 +184,15 @@ function Tags({ viewer, data, onAction, ...props }) {
); );
} }
/* -------------------------------------------------------------------------------------------------
* Following
* -----------------------------------------------------------------------------------------------*/
function Following({ viewer, onAction, ...props }) { function Following({ viewer, onAction, ...props }) {
const [, { hidePopup }] = useFilterContext(); const [, { hidePopup }] = useFilterContext();
return ( return (
<RovingTabIndex.Provider axis="vertical"> <FilterSection title="Following" emptyState="follow users to see them here" {...props}>
<RovingTabIndex.List>
<FilterSection title="Following" {...props}>
{viewer.following.map((user, index) => ( {viewer.following.map((user, index) => (
<li key={user.id}> <li key={user.id}>
<RovingTabIndex.Item index={index}> <RovingTabIndex.Item index={index}>
@ -199,11 +210,13 @@ function Following({ viewer, onAction, ...props }) {
</li> </li>
))} ))}
</FilterSection> </FilterSection>
</RovingTabIndex.List>
</RovingTabIndex.Provider>
); );
} }
/* -------------------------------------------------------------------------------------------------
* Profile
* -----------------------------------------------------------------------------------------------*/
function Profile({ viewer, data, page, ...props }) { function Profile({ viewer, data, page, ...props }) {
if (page.id === "NAV_SLATE") { if (page.id === "NAV_SLATE") {
data = data.owner; data = data.owner;
@ -288,6 +301,10 @@ function Profile({ viewer, data, page, ...props }) {
); );
} }
/* -------------------------------------------------------------------------------------------------
* ProfileTags
* -----------------------------------------------------------------------------------------------*/
function ProfileTags({ data, page, onAction, ...props }) { function ProfileTags({ data, page, onAction, ...props }) {
const [, { hidePopup }] = useFilterContext(); const [, { hidePopup }] = useFilterContext();
@ -297,8 +314,6 @@ function ProfileTags({ data, page, onAction, ...props }) {
} }
return ( return (
<RovingTabIndex.Provider axis="vertical">
<RovingTabIndex.List>
<FilterSection {...props}> <FilterSection {...props}>
{user?.slates?.map((slate, index) => ( {user?.slates?.map((slate, index) => (
<li key={slate.id}> <li key={slate.id}>
@ -316,8 +331,6 @@ function ProfileTags({ data, page, onAction, ...props }) {
</li> </li>
))} ))}
</FilterSection> </FilterSection>
</RovingTabIndex.List>
</RovingTabIndex.Provider>
); );
} }