Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(website): add Sidebar docs and fix minor component types #3217

Merged
merged 30 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e9c063d
fix(sidebar): type fixe
TheSisb May 5, 2023
dc663f3
fix(sidebar): dont pass onClick through when as=span on badge
TheSisb May 5, 2023
4d2eba2
docs: add Sidebar docs page
TheSisb May 5, 2023
b701d84
fix: lint fix
TheSisb May 5, 2023
f13bf88
fix: danger check
TheSisb May 5, 2023
5975715
chore: updated docs with more details about the child components
SiTaggart May 22, 2023
772b106
chore: linting imports
SiTaggart May 23, 2023
f9d114b
chore: sidebar dep
SiTaggart May 23, 2023
96b77fa
Merge branch 'main' into sidebar-docs
SiTaggart May 25, 2023
0e62883
chore: website deps
SiTaggart May 25, 2023
1a2159b
Merge branch 'main' into sidebar-docs
SiTaggart Jun 13, 2023
495698b
chore: updates to sidebar and full compositions
SiTaggart Jun 21, 2023
e44e3b1
feat: update the notifications, debugger, alarms
SiTaggart Jun 22, 2023
9a4f5b5
chore: pr feedback
SiTaggart Jun 22, 2023
c3bb9b7
chore: types
SiTaggart Jun 22, 2023
9e376f5
chore: icon colors for topbar
SiTaggart Jun 23, 2023
cbfcb68
chore: visual fixes to sidebar indentatinos
SiTaggart Jun 26, 2023
8ef7cfd
chore: lint and build
SiTaggart Jun 26, 2023
9d70e95
chore: lint
SiTaggart Jun 26, 2023
162fc6e
chore: changeset
SiTaggart Jun 26, 2023
5ef6a55
chore: implement hidden search box label in stories
SiTaggart Jun 26, 2023
077b769
Merge branch 'main' into sidebar-docs
SiTaggart Jun 27, 2023
264d16e
docs: sidebar docs
SiTaggart Jun 28, 2023
d1b4277
fix: scroll gradient
SiTaggart Jun 28, 2023
6781a06
Merge branch 'main' into sidebar-docs
SiTaggart Jun 28, 2023
97806cf
chore: lockfile
SiTaggart Jun 28, 2023
da96070
chore: packages after release
SiTaggart Jun 28, 2023
d3be530
Merge branch 'main' into sidebar-docs
SiTaggart Jun 28, 2023
d895cb6
chore: minor test tweaks
SiTaggart Jun 28, 2023
0167b5b
chore: final go
SiTaggart Jun 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/neat-mugs-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@twilio-paste/sidebar': patch
'@twilio-paste/core': patch
---

[Sidebar] `SidebarBetaBadge` no longer passes `onClick` when `as="span"`. Other miscellaneous typescript fixes.
1 change: 1 addition & 0 deletions cypress/integration/sitemap-vrt/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const SITEMAP = [
'/components/screen-reader-only/',
'/components/select/',
'/components/separator/',
'/components/sidebar/',
'/components/stack/',
'/components/status-badge/',
'/components/status-menu/',
Expand Down
47 changes: 23 additions & 24 deletions packages/paste-core/components/sidebar/src/SidebarBetaBadge.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import {Box, safelySpreadBoxProps} from '@twilio-paste/box';
import type {BoxProps} from '@twilio-paste/box';
import {badgeBaseStyles, useResizeChildIcons} from '@twilio-paste/badge';
import type {BadgeProps} from '@twilio-paste/badge';

const SidebarBetaBadgeSpanStyles: BoxProps = {
...badgeBaseStyles,
paddingX: 'space20',
paddingY: 'space10',
boxShadow: 'shadowBorderInverseNewWeaker',
backgroundColor: 'colorBackgroundInverseStrong',
color: 'colorTextInverseNew',
};
const SidebarBetaBadgeButtonStyles: BoxProps = {
...SidebarBetaBadgeSpanStyles,
boxShadow: 'shadowBorderBottomInverseNewWeaker',
// The following styles are copied from getBadgeButtonStyles() in the Badge package
cursor: 'pointer',
_hover: {top: '1px', boxShadow: 'none'},
_focus: {top: '1px', boxShadow: 'shadowFocusInverse'}, // shadowFocus in Badge
};

type SidebarBetaBadgeProps = Omit<BadgeProps, 'as' | 'variant' | 'size'> & {
as: 'span' | 'button';
};

export const SidebarBetaBadge = React.forwardRef<HTMLElement, SidebarBetaBadgeProps>(
({children, as, element = 'SIDEBAR_BETA_BADGE', ...props}, ref) => {
({children, as, element = 'SIDEBAR_BETA_BADGE', onClick, ...props}, ref) => {
const resizedChildren = useResizeChildIcons(children);
let badgeStyles = badgeBaseStyles;

if (as === 'button') {
badgeStyles = {
...badgeStyles,
// The following styles are copied from getBadgeButtonStyles() in the Badge package
cursor: 'pointer',
_hover: {top: '1px', boxShadow: 'none'},
_focus: {top: '1px', boxShadow: 'shadowFocusInverse'}, // shadowFocus in Badge
};
}
const styles = as === 'button' ? SidebarBetaBadgeButtonStyles : SidebarBetaBadgeSpanStyles;
// We don't want the provided onClick to function if as = span
const handleOnClick = as === 'button' ? onClick : undefined;

return (
<Box
{...safelySpreadBoxProps(props)}
{...badgeStyles}
paddingX="space20"
paddingY="space10"
boxShadow={as === 'button' ? 'shadowBorderBottomInverseNewWeaker' : 'shadowBorderInverseNewWeaker'}
backgroundColor="colorBackgroundInverseStrong"
color="colorTextInverseNew"
as={as}
ref={ref}
element={element}
>
<Box {...safelySpreadBoxProps(props)} {...styles} as={as} ref={ref} element={element} onClick={handleOnClick}>
{resizedChildren}
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import {Button} from '@twilio-paste/button';
import type {ButtonProps} from '@twilio-paste/button';
import type {BoxProps} from '@twilio-paste/box';
import {ScreenReaderOnly} from '@twilio-paste/screen-reader-only';
import {ChevronDoubleLeftIcon} from '@twilio-paste/icons/esm/ChevronDoubleLeftIcon';
Expand All @@ -13,7 +12,6 @@ export interface SidebarCollapseButtonProps extends React.HTMLAttributes<HTMLBut
i18nCollapseLabel: string;
i18nExpandLabel: string;
element?: BoxProps['element'];
tabIndex?: ButtonProps['tabIndex'];
onClick?: () => void;
}

Expand All @@ -28,6 +26,7 @@ export const SidebarCollapseButton = React.forwardRef<HTMLButtonElement, Sidebar
variant="inverse"
element={element}
{...props}
tabIndex={0}
aria-expanded={!collapsed}
aria-controls={sidebarId}
>
Expand All @@ -52,7 +51,6 @@ SidebarCollapseButton.propTypes = {
i18nExpandLabel: PropTypes.string.isRequired,
element: PropTypes.string,
onClick: PropTypes.func,
tabIndex: PropTypes.oneOf([-1, 0]),
};

SidebarCollapseButton.displayName = 'SidebarCollapseButton';
6 changes: 2 additions & 4 deletions packages/paste-core/components/sidebar/src/SidebarHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {Box, safelySpreadBoxProps} from '@twilio-paste/box';
import type {BoxProps} from '@twilio-paste/box';

export interface SidebarHeaderProps extends React.HTMLAttributes<HTMLButtonElement> {
productIcon?: React.ReactNode;
onClick?: () => void;
children: React.ReactNode;
element?: BoxProps['element'];
}

Expand Down Expand Up @@ -34,9 +33,8 @@ export const SidebarHeader = React.forwardRef<HTMLButtonElement, SidebarHeaderPr
);

SidebarHeader.propTypes = {
productIcon: PropTypes.node,
children: PropTypes.node,
element: PropTypes.string,
onClick: PropTypes.func,
};

SidebarHeader.displayName = 'SidebarHeader';
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import type {BoxProps} from '@twilio-paste/box';

export interface SidebarHeaderIconButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
children: NonNullable<React.ReactNode>;
tabIndex?: ButtonProps['tabIndex'];
onClick?: () => void;
as: 'a' | 'button';
onClick?: ButtonProps['onClick'];
href?: ButtonProps['href'];
element?: BoxProps['element'];
}

export const SidebarHeaderIconButton = React.forwardRef<HTMLButtonElement, SidebarHeaderIconButtonProps>(
({element = 'SIDEBAR_HEADER_ICON_BUTTON', ...props}, ref) => {
return <Button {...props} size="icon" variant="inverse" element={element} ref={ref} />;
return <Button {...props} tabIndex={0} size="icon" variant="inverse" element={element} ref={ref} />;
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import type {StoryFn} from '@storybook/react';

import {SidebarBetaBadge} from '../src';

// eslint-disable-next-line import/no-default-export
export default {
title: 'Components/Sidebar',
};

export const BetaBadge: StoryFn = () => {
return <SidebarBetaBadge as="span">Beta</SidebarBetaBadge>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import {Box} from '@twilio-paste/box';
import type {StoryFn} from '@storybook/react';
import {LogoTwilioIcon} from '@twilio-paste/icons/esm/LogoTwilioIcon';

import {SidebarHeader, SidebarHeaderLabel, SidebarHeaderIconButton} from '../src';

// eslint-disable-next-line import/no-default-export
export default {
title: 'Components/Sidebar',
};

export const Header: StoryFn = () => {
return (
<Box backgroundColor="colorBackgroundInverse" maxWidth="size50">
<SidebarHeader>
<SidebarHeaderIconButton href="#" as="a">
<LogoTwilioIcon size="sizeIcon20" decorative={false} title="Go to Console homepage" />
</SidebarHeaderIconButton>
<SidebarHeaderLabel>Twilio Console</SidebarHeaderLabel>
</SidebarHeader>
</Box>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {

// eslint-disable-next-line import/no-default-export
export default {
title: 'Components/Sidebar/Customization',
title: 'Components/Sidebar/Sidebar/Customization',
};

export const WithDefaultElementName: StoryFn = (_args, {parameters: {isTestEnvironment}}) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as React from 'react';
import {Button} from '@twilio-paste/button';
import {Stack} from '@twilio-paste/stack';
import {Box} from '@twilio-paste/box';
import type {StoryFn} from '@storybook/react';
import {LogoTwilioIcon} from '@twilio-paste/icons/esm/LogoTwilioIcon';
// ONLY for storybook stacked view not to complain on duplicates. aria-label should be carefully selected strings
import {useUID} from '@twilio-paste/uid-library';
import {Topbar} from '@twilio-paste/topbar';

import {
Sidebar,
SidebarHeader,
SidebarHeaderLabel,
SidebarHeaderIconButton,
SidebarCollapseButton,
SidebarCollapseButtonWrapper,
SidebarPushContentWrapper,
} from '../../src';

// eslint-disable-next-line import/no-default-export
export default {
title: 'Components/Sidebar/FullCompositions',
};

export const Console: StoryFn = () => {
const id = useUID();
const [pushSidebarCollapsed, setPushSidebarCollapsed] = React.useState(false);

return (
<Box>
{/* Can be placed anywhere - position fixed */}
<Sidebar aria-label={id} collapsed={pushSidebarCollapsed} variant="compact">
<Stack orientation="vertical" spacing="space100">
<SidebarHeader>
<SidebarHeaderIconButton as="a" href="#">
<LogoTwilioIcon size="sizeIcon20" decorative={false} title="Go to Console homepage" />
</SidebarHeaderIconButton>
<SidebarHeaderLabel>Twilio Console</SidebarHeaderLabel>
</SidebarHeader>
<SidebarCollapseButtonWrapper>
<SidebarCollapseButton
onClick={() => setPushSidebarCollapsed(!pushSidebarCollapsed)}
i18nCollapseLabel="Close sidebar"
i18nExpandLabel="Open sidebar"
/>
</SidebarCollapseButtonWrapper>
</Stack>
</Sidebar>

{/* Must wrap content area */}
<SidebarPushContentWrapper collapsed={pushSidebarCollapsed} variant="compact">
<Topbar>topbar</Topbar>
<Box padding="space70">
<Button variant="primary" onClick={() => setPushSidebarCollapsed(!pushSidebarCollapsed)}>
Toggle Push Sidebar
</Button>
</Box>
</SidebarPushContentWrapper>
</Box>
);
};
Console.parameters = {
padding: false,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as React from 'react';
import {Button} from '@twilio-paste/button';
import {Stack} from '@twilio-paste/stack';
import {Box} from '@twilio-paste/box';
import type {StoryFn} from '@storybook/react';
import {ProductFlexIcon} from '@twilio-paste/icons/esm/ProductFlexIcon';
// ONLY for storybook stacked view not to complain on duplicates. aria-label should be carefully selected strings
import {useUID} from '@twilio-paste/uid-library';
import {Topbar} from '@twilio-paste/topbar';

import {
Sidebar,
SidebarHeader,
SidebarHeaderLabel,
SidebarHeaderIconButton,
SidebarCollapseButton,
SidebarCollapseButtonWrapper,
SidebarOverlayContentWrapper,
} from '../../src';

// eslint-disable-next-line import/no-default-export
export default {
title: 'Components/Sidebar/FullCompositions',
};

export const Flex: StoryFn = () => {
const id = useUID();
const [overlaySidebarExpanded, setOverlaySidebarExpanded] = React.useState(true);

return (
<Box>
{/* Can be placed anywhere - position fixed */}
<Sidebar aria-label={id} collapsed={overlaySidebarExpanded} variant="compact">
<Stack orientation="vertical" spacing="space100">
<SidebarHeader>
<SidebarHeaderIconButton as="a" href="#">
<ProductFlexIcon size="sizeIcon20" decorative={false} title="Go to Flex homepage" />
</SidebarHeaderIconButton>
<SidebarHeaderLabel>Twilio Flex</SidebarHeaderLabel>
</SidebarHeader>
<SidebarCollapseButtonWrapper>
<SidebarCollapseButton
onClick={() => setOverlaySidebarExpanded(!overlaySidebarExpanded)}
i18nCollapseLabel="Close sidebar"
i18nExpandLabel="Open sidebar"
/>
</SidebarCollapseButtonWrapper>
</Stack>
</Sidebar>

{/* Must wrap content area */}
<SidebarOverlayContentWrapper collapsed={overlaySidebarExpanded} variant="compact">
<Topbar>topbar</Topbar>
<Box padding="space70">
<Button variant="primary" onClick={() => setOverlaySidebarExpanded(!overlaySidebarExpanded)}>
Toggle Overlay Sidebar
</Button>
</Box>
</SidebarOverlayContentWrapper>
</Box>
);
};
Flex.parameters = {
padding: false,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as React from 'react';
import {Button} from '@twilio-paste/button';
import {Stack} from '@twilio-paste/stack';
import {Box} from '@twilio-paste/box';
import type {StoryFn} from '@storybook/react';
import {ProductSegmentIcon} from '@twilio-paste/icons/esm/ProductSegmentIcon';
// ONLY for storybook stacked view not to complain on duplicates. aria-label should be carefully selected strings
import {useUID} from '@twilio-paste/uid-library';
import {Topbar} from '@twilio-paste/topbar';

import {
Sidebar,
SidebarHeader,
SidebarHeaderLabel,
SidebarHeaderIconButton,
SidebarCollapseButton,
SidebarCollapseButtonWrapper,
SidebarPushContentWrapper,
} from '../../src';

// eslint-disable-next-line import/no-default-export
export default {
title: 'Components/Sidebar/FullCompositions',
};

export const Segment: StoryFn = () => {
const id = useUID();
const [pushSidebarCollapsed, setPushSidebarCollapsed] = React.useState(false);

return (
<Box>
{/* Can be placed anywhere - position fixed */}
<Sidebar aria-label={id} collapsed={pushSidebarCollapsed} variant="compact">
<Stack orientation="vertical" spacing="space100">
<SidebarHeader>
<SidebarHeaderIconButton as="a" href="#">
<ProductSegmentIcon size="sizeIcon20" decorative={false} title="Go to Segment homepage" />
</SidebarHeaderIconButton>
<SidebarHeaderLabel>Twilio Segment</SidebarHeaderLabel>
</SidebarHeader>
<SidebarCollapseButtonWrapper>
<SidebarCollapseButton
onClick={() => setPushSidebarCollapsed(!pushSidebarCollapsed)}
i18nCollapseLabel="Close sidebar"
i18nExpandLabel="Open sidebar"
/>
</SidebarCollapseButtonWrapper>
</Stack>
</Sidebar>

{/* Must wrap content area */}
<SidebarPushContentWrapper collapsed={pushSidebarCollapsed} variant="compact">
<Topbar>topbar</Topbar>
<Box padding="space70">
<Button variant="primary" onClick={() => setPushSidebarCollapsed(!pushSidebarCollapsed)}>
Toggle Push Sidebar
</Button>
</Box>
</SidebarPushContentWrapper>
</Box>
);
};
Segment.parameters = {
padding: false,
};