From 5d1380c4d28a0b6c715884ca1ce18d6f03ad0a11 Mon Sep 17 00:00:00 2001 From: Armagan Ersoz Date: Wed, 16 Nov 2022 19:34:53 +1000 Subject: [PATCH] Add controls --- src/PageHeader/PageHeader.stories.tsx | 297 ++++++++++++++++++++++++-- src/PageHeader/PageHeader.tsx | 170 +++++++++------ 2 files changed, 383 insertions(+), 84 deletions(-) diff --git a/src/PageHeader/PageHeader.stories.tsx b/src/PageHeader/PageHeader.stories.tsx index 98ada389548..5f6cfa67f4e 100644 --- a/src/PageHeader/PageHeader.stories.tsx +++ b/src/PageHeader/PageHeader.stories.tsx @@ -1,11 +1,26 @@ import React from 'react' import {Meta, Story} from '@storybook/react' -import {Button, IconButton, Breadcrumbs} from '..' +import {Button, IconButton, Breadcrumbs, Link, Text, StateLabel, BranchName} from '..' +import {UnderlineNav} from '../UnderlineNav2' import Label from '../Label' -import {PencilIcon, KebabHorizontalIcon, GitBranchIcon} from '@primer/octicons-react' +import { + KebabHorizontalIcon, + GitBranchIcon, + CodeIcon, + GitPullRequestIcon, + PeopleIcon, + PencilIcon, + CommentDiscussionIcon, + CommitIcon, + ChecklistIcon, + FileDiffIcon, + ArrowRightIcon +} from '@primer/octicons-react' +import {OcticonArgType} from '../utils/story-helpers' import {PageHeader} from './PageHeader' import Hidden from '../Hidden' +import {Actions} from '../drafts/MarkdownEditor/Actions' const meta: Meta = { title: 'Drafts/Components/PageHeader', @@ -13,15 +28,201 @@ const meta: Meta = { layout: 'fullscreen', controls: {expanded: true} }, - args: {} + args: { + isContextAreaVisible: true, + ParentLink: 'Previous Page', + 'ParentLink.hidden': false, + 'ContextBar.hidden': true, + 'ContextAreaAction.hidden': true, + 'BackButton.hidden': true, + Title: 'Branches', + 'Title.as': 'h2', + 'Title.variant': 'medium', + LeadingVisual: GitBranchIcon, + 'LeadingVisual.hidden': false, + 'TrailingVisual.hidden': false, + 'TrailingAction.hidden': false, + 'Description.hidden': false, + 'Navigation.hidden': false + }, + argTypes: { + isContextAreaVisible: { + type: 'boolean', + table: { + category: 'ContextArea Slot' + } + }, + ParentLink: { + type: 'string', + if: {arg: 'isContextAreaVisible'}, + table: { + category: 'ContextArea Slot' + }, + description: 'The default way to let users navigate up in the hierarchy on Narrow viewports.' + }, + 'ParentLink.hidden': { + type: 'boolean', + if: {arg: 'isContextAreaVisible'}, + table: { + category: 'ContextArea Slot' + }, + description: 'Parent ' + }, + 'ContextBar.hidden': { + type: 'boolean', + if: {arg: 'isContextAreaVisible'}, + table: { + category: 'ContextArea Slot' + }, + description: + 'ContextBar is generic slot for any component above the title region. Use it for custom breadcrumbs and other navigation elements instead of ParentLink.' + }, + 'ContextAreaAction.hidden': { + type: 'boolean', + if: {arg: 'isContextAreaVisible'}, + table: { + category: 'ContextArea Slot' + } + }, + 'BackButton.hidden': { + type: 'boolean', + table: { + category: 'TitleArea Slot' + }, + description: + 'A back button can be used as a leading action for local navigation. On Narrow viewports, use parentLink instead.' + }, + Title: { + type: 'string', + table: { + category: 'TitleArea Slot' + } + }, + 'Title.as': { + control: { + type: 'select' + }, + options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'], + table: { + category: 'TitleArea Slot' + } + }, + 'Title.variant': { + control: { + type: 'radio' + }, + options: ['large', 'medium', 'subtitle'], + table: { + category: 'TitleArea Slot' + }, + description: + '`medium` is the most common page title size. Use for static titles in most situations. `large` for for user-generated content such as issues, pull requests, or discussions. `subtitle` when a PageHeader.Title is already present in the page, such as in a SplitPageLayout.' + }, + LeadingVisual: { + ...OcticonArgType([CodeIcon, GitPullRequestIcon, PeopleIcon]), + table: {category: 'TitleArea Slot'}, + description: + 'Leading visualLeading visuals are optional and appear at the start of the title. They can be octicons, avatars, and other custom visuals that fit a small area.' + }, + 'LeadingVisual.hidden': { + type: 'boolean', + table: { + category: 'TitleArea Slot' + } + }, + 'TrailingVisual.hidden': { + type: 'boolean', + table: { + category: 'TitleArea Slot' + }, + description: + 'Trailing visualTrailing visual and trailing text can display auxiliary information. They are placed at the right of the item, and can denote status, privacy details, etc.' + }, + 'TrailingAction.hidden': { + type: 'boolean', + table: { + category: 'TitleArea Slot' + } + }, + 'Actions.hidden': { + type: 'boolean', + table: { + category: 'TitleArea Slot' + }, + description: 'Description region/slot' + }, + Description: { + table: { + category: 'Other Slots' + }, + description: 'Description Slots' + }, + 'Description.hidden': { + type: 'boolean', + table: { + category: 'Other Slots' + }, + description: 'Description region/slot' + }, + Navigation: { + table: { + category: 'Other Slots' + }, + description: 'Navigation Slots' + }, + 'Navigation.hidden': { + type: 'boolean', + table: { + category: 'Other Slots' + }, + description: 'Description region/slot' + } + } } +// TODO: THink about it after lunch. +// context bar action visiblity doesn't work because the context bar has upper layer visibility. +// You might want to set conditional visibility on the context bar itself. + // eslint-disable-next-line @typescript-eslint/no-unused-vars const Template: Story = args => ( - - Code - + - - - + + + ) diff --git a/src/PageHeader/PageHeader.tsx b/src/PageHeader/PageHeader.tsx index 1496465190c..d67cbd440a3 100644 --- a/src/PageHeader/PageHeader.tsx +++ b/src/PageHeader/PageHeader.tsx @@ -20,26 +20,32 @@ Reference figma - https://www.figma.com/file/Ee0OrXuOLXMDqUW83EnDHP/PageHeader-( const REGION_ORDER = { ContextArea: 0, - titleArea: 1, - description: 2, + TitleArea: 1, + Description: 2, Navigation: 3 } -// Root -// ----------------------------------------------------------------------------- -export type PageHeaderProps = { + +// Types that are shared between sub components +export type sharedPropTypes = { hidden?: boolean | ResponsiveValue } & SxProp +// Default state for the `hidden` prop when a sub component is only visible on narrow viewport +const onlyVisibleOnNarrowView = { + narrow: false, + regular: true, + wide: true +} + +// Root +// ----------------------------------------------------------------------------- +export type PageHeaderProps = sharedPropTypes + const Root: React.FC> = ({children, sx = {}}) => { const rootStyles = { - marginX: 'auto', display: 'flex', - flexDirection: 'column', - flexWrap: 'wrap', - flexBasis: 0, - flexGrow: 1, - flexShrink: 1, - minWidth: 1 + flexDirection: 'column' + // flexWrap: 'wrap' } return (rootStyles, sx)}>{children} } @@ -48,17 +54,10 @@ const Root: React.FC> = ({children, sx // to manage their custom visibility but consumers should be careful to hide this on narrow viewports. // PageHeader.ContexArea Sub Components: PageHeader.ParentLink, PageHeader.ContextBar, PageHeader.ContextNavActions // --------------------------------------------------------------------- -export type ContextAreaProps = { - hidden?: boolean | ResponsiveValue -} & SxProp -const ContextArea: React.FC> = ({ +const ContextArea: React.FC> = ({ children, - hidden = { - narrow: false, - regular: true, - wide: true - }, + hidden = onlyVisibleOnNarrowView, sx = {} }) => { const isHidden = useResponsiveValue(hidden, false) @@ -78,26 +77,21 @@ const ContextArea: React.FC> = ({ export type ParentLinkProps = { href?: string - hidden?: boolean | ResponsiveValue -} & SxProp +} & PageHeaderProps const ParentLink: React.FC> = ({ children, sx = {}, href, - hidden = { - narrow: false, - regular: true, - wide: true - } + hidden = onlyVisibleOnNarrowView }) => { const isHidden = useResponsiveValue(hidden, false) + // console.log('is hidden', isHidden) return ( <> ({display: 'flex', alignItems: 'center'}, sx)} + sx={merge({display: isHidden ? ' none' : 'flex', alignItems: 'center'}, sx)} href={href} > @@ -111,18 +105,10 @@ const ParentLink: React.FC> = ({ // Generic slot for any component above the title region. Use it for custom breadcrumbs and other navigation elements instead of ParentLink. // --------------------------------------------------------------------- -export type ContextBarProps = { - hidden?: boolean | ResponsiveValue -} & SxProp - const ContextBar: React.FC> = ({ children, sx = {}, - hidden = { - narrow: false, - regular: true, - wide: true - } + hidden = onlyVisibleOnNarrowView }) => { const isHidden = useResponsiveValue(hidden, false) return ( @@ -134,25 +120,19 @@ const ContextBar: React.FC> = ({ // ContextAreaActions // --------------------------------------------------------------------- -export type ContextAreaActionsProps = { - hidden?: boolean | ResponsiveValue -} & SxProp -const ContextAreaActions: React.FC> = ({ +const ContextAreaActions: React.FC> = ({ children, sx = {}, - hidden = { - narrow: false, - regular: true, - wide: true - } + hidden = onlyVisibleOnNarrowView }) => { const isHidden = useResponsiveValue(hidden, false) + console.log({hidden}, {isHidden}) return (