import { DescriptiveAt } from '@repay/cactus-icons' import { Page } from 'puppeteer' import React from 'react' import styled from 'styled-components' import { ActionBar, Box, BrandBar, Divider, Flex, Layout, Link, SelectField, SIZES, Text, TextInput, useScreenSize, } from '../' import { Story, STRING } from '../helpers/storybook' import { insetBorder } from '../helpers/theme' import { SelectValueType } from '../Select/Select' interface Org { name: string id: string subdomain: string } const ORGS: { favorites: Org[]; recent: Org[] } = { favorites: [ { name: 'Test Org', id: '123456', subdomain: 'test-org', }, { name: 'Faker', id: '123465', subdomain: 'faker', }, { name: 'Favorite', id: '213456', subdomain: 'fav', }, ], recent: [ { name: 'Most Recent', id: '654321', subdomain: 'most-recent', }, { name: 'My Org', id: '654312', subdomain: 'my-org', }, { name: 'Fleeting', id: '124356', subdomain: 'fleeting', }, { name: 'Low', id: '987654', subdomain: 'low-life', }, ], } const LOGO = 'https://repay-merchant-resources.s3.amazonaws.com/staging/24bd1970-a677-4ca7-a4d2-e328ddd4691b/repay_logo_new.jpg' const action = (msg: string) => () => console.log(msg) export default { title: 'BrandBar', component: BrandBar, argTypes: { logo: STRING }, args: { logo: LOGO }, } as const type LogoArg = { logo: string } export const BasicUsage: Story< { isProfilePage: boolean menuLabel: string userMenuItems: string[] } & LogoArg > = ({ isProfilePage, menuLabel, userMenuItems, logo }) => ( {userMenuItems.map((item, ix) => ( {item} ))} Go to Google ) BasicUsage.argTypes = { isProfilePage: { name: 'is on profile page' }, menuLabel: { name: 'user display name' }, userMenuItems: { name: 'user menu actions' }, } BasicUsage.args = { isProfilePage: false, menuLabel: 'Hershell Jewess', userMenuItems: ['Settings', 'Logout'], } export const CustomItems: Story< { moveItem: boolean } & LogoArg > = ({ logo, moveItem }): React.ReactElement => { const [org, setOrg] = React.useState('OWE') const onOrgChange = React.useCallback( (e: React.ChangeEvent<{ value: SelectValueType }>) => setOrg(e.target.value), [setOrg] ) const icon = moveItem ? : undefined return ( Settings Logout ) } CustomItems.argTypes = { moveItem: { name: 'move org select to ActionBar' } } CustomItems.args = { moveItem: false } CustomItems.parameters = { beforeScreenshot: async (page: Page) => { await page.click('[id="org-select"]') await page.focus('[id="org-select-REPAY"]') }, } BasicUsage.parameters = { beforeScreenshot: async (page: Page) => { await page.click('[role="button"]') await page.focus('[role="menuitem"]') }, } const List = styled.ul` margin: 0; padding: 0; ` const ListItem = styled.li<{ $isLastItem: boolean }>` padding: ${(p) => p.theme.space[2]}px; border-bottom: ${(p) => (p.$isLastItem ? 'none' : `1px solid ${p.theme.colors.lightContrast}`)}; cursor: pointer; list-style-type: none; outline: none; &:focus { color: ${(p) => p.theme.colors.callToAction}; ${(p) => insetBorder(p.theme, 'callToAction')}; } &:hover { color: ${(p) => p.theme.colors.callToAction}; } ` type AlignArgs = LogoArg & { align: 'right' | 'left' } const BrandBarWithOrgDropdown = ({ logo, align }: AlignArgs) => { /* * Had to pull this into a separate component so we could use the * useScreenSize() hook. */ const [currentOrg, setCurrentOrg] = React.useState(ORGS.favorites[0]) const [searchValue, setSearchValue] = React.useState('') const [searchedOrgs, setSearchedOrgs] = React.useState([]) const isTiny = SIZES.tiny === useScreenSize() React.useEffect(() => { if (searchValue) { setSearchedOrgs( [...ORGS.favorites, ...ORGS.recent].filter((org) => org.name.includes(searchValue)) ) } }, [searchValue]) const handleOrgSelect = (orgId: string) => { const newOrg = [...ORGS.favorites, ...ORGS.recent].find((org) => org.id === orgId) setCurrentOrg(newOrg as Org) setSearchValue('') } return ( {currentOrg.name} Some Custom Content { setSearchValue(e.target.value) }} /> {searchValue ? ( {searchedOrgs.map((org, ix) => ( handleOrgSelect(org.id)} > {org.name} ))} ) : ( <> Current Org Info {currentOrg.name} {currentOrg.id} {currentOrg.subdomain} Favorites {ORGS.favorites.map((org, ix) => ( handleOrgSelect(org.id)} > {org.name} ))} Recents {ORGS.recent.map((org, ix) => ( handleOrgSelect(org.id)} > {org.name} ))} )} Settings Logout ) } export const WithOrgDropdown: Story = (args) => { return ( ) } WithOrgDropdown.argTypes = { align: { options: ['left', 'right'] } } WithOrgDropdown.args = { align: 'right' } WithOrgDropdown.parameters = { beforeScreenshot: async (page: Page) => { await page.click('[role="button"]') await page.focus('[role="menuitem"]') }, }