Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
35148a5
feat(react-drawer): create body component
marcosmoura Apr 17, 2023
ca1a90f
Merge branch 'master' into feat/drawer-components
marcosmoura Apr 17, 2023
8a1bafc
Merge branch 'master' into feat/drawer-components
marcosmoura Apr 18, 2023
49e55d3
fix: remove .cy files from lib config
marcosmoura Apr 18, 2023
ca1a06e
fix: remove .cy files from lib config
marcosmoura Apr 18, 2023
1867b3d
Merge branch 'master' into feat/drawer-components
marcosmoura Apr 24, 2023
e98fc9e
Merge branch 'master' into feat/drawer-components
marcosmoura Apr 25, 2023
aee85b9
fix: remove conflict code leftover
marcosmoura Apr 25, 2023
b61d019
docs: remove TODO marks
marcosmoura Apr 25, 2023
2190a1f
docs: add TODO indicator
marcosmoura Apr 25, 2023
13b2226
Merge branch 'master' into feat/drawer-components
marcosmoura Apr 25, 2023
c9c3efd
feat: add support to override drawer body styles
marcosmoura Apr 27, 2023
5e7224b
test: add cypress tests for scroll positions
marcosmoura Apr 27, 2023
7ea5df2
fix: rename styles file to use the newer naming conventions
marcosmoura Apr 27, 2023
cbca31c
Merge branch 'master' into feat/drawer-components
marcosmoura Apr 27, 2023
7e22ce8
Merge branch 'master' into feat/drawer-components
marcosmoura Apr 27, 2023
8f76678
fix: prevent elements from stretching
marcosmoura Apr 27, 2023
7035ce5
feat: add support to override drawer styles
marcosmoura Apr 27, 2023
bf14755
feat: add style overrides for upcoming drawer components
marcosmoura Apr 27, 2023
b2c81eb
docs: update API
marcosmoura Apr 27, 2023
8547ea6
Merge branch 'master' into feat/drawer-components
marcosmoura May 2, 2023
355e444
docs: update API
marcosmoura May 2, 2023
4b6570f
Merge branch 'master' into feat/drawer-components
marcosmoura May 2, 2023
9ff3422
Merge branch 'master' into feat/drawer-components
marcosmoura May 2, 2023
d287cbb
fix: add missing change file
marcosmoura May 2, 2023
c195885
test: merge tests
marcosmoura May 3, 2023
83cf470
fix: add changefiles
marcosmoura May 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/react-components/react-drawer/etc/react-drawer.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,30 @@ import type { SlotClassNames } from '@fluentui/react-utilities';
// @public
export const Drawer: ForwardRefComponent<DrawerProps>;

// @public
export const DrawerBody: ForwardRefComponent<DrawerBodyProps>;

// @public (undocumented)
export const drawerBodyClassNames: SlotClassNames<DrawerBodySlots>;

// @public
export type DrawerBodyProps = ComponentProps<DrawerBodySlots> & {};

// @public (undocumented)
export type DrawerBodySlots = {
root: Slot<'div'>;
};

// @public
export type DrawerBodyState = ComponentState<DrawerBodySlots>;

// @public (undocumented)
export const drawerClassNames: SlotClassNames<DrawerSlots>;

// @public
export const drawerCSSVars: {
size: string;
borderRadius: string;
};

// @public
Expand All @@ -49,9 +67,18 @@ export type DrawerState = ComponentState<DrawerSlots> & Required<Pick<DrawerProp
// @public
export const renderDrawer_unstable: (state: DrawerState) => JSX.Element | null;

// @public
export const renderDrawerBody_unstable: (state: DrawerBodyState) => JSX.Element;

// @public
export const useDrawer_unstable: (props: DrawerProps, ref: React_2.Ref<HTMLElement>) => DrawerState;

// @public
export const useDrawerBody_unstable: (props: DrawerBodyProps, ref: React_2.Ref<HTMLElement>) => DrawerBodyState;

// @public
export const useDrawerBodyStyles_unstable: (state: DrawerBodyState) => DrawerBodyState;

// @public
export const useDrawerStyles_unstable: (state: DrawerState) => DrawerState;

Expand Down
3 changes: 2 additions & 1 deletion packages/react-components/react-drawer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"type-check": "tsc -b tsconfig.json",
"generate-api": "just-scripts generate-api",
"storybook": "start-storybook",
"start": "yarn storybook"
"start": "yarn storybook",
"test-ssr": "test-ssr ./stories/**/*.stories.tsx"
},
"devDependencies": {
"@fluentui/eslint-plugin": "*",
Expand Down
1 change: 1 addition & 0 deletions packages/react-components/react-drawer/src/DrawerBody.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/DrawerBody/index';
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,6 @@ import { DialogProps } from '@fluentui/react-dialog';

import type { DrawerProps, DrawerState } from './Drawer.types';

/**
* @internal
* Create the state required to render DrawerDialog.
* @param props - props from this instance of Drawer
*/
const useDrawerDialogProps = (props: DrawerProps) => {
const { open, onOpenChange, modal, children, ...otherProps } = props;

const dialogProps = React.useMemo(() => {
return {
open,
onOpenChange,
modalType: modal ? 'modal' : 'non-modal',
children,
} as DialogProps;
}, [children, modal, onOpenChange, open]);

const dialogSurfaceProps = React.useMemo(() => {
return {
...otherProps,
children,
};
}, [children, otherProps]);

return {
dialog: dialogProps,
dialogSurface: dialogSurfaceProps,
};
};

/**
* Create the state required to render Drawer.
*
Expand All @@ -50,8 +20,11 @@ export const useDrawer_unstable = (props: DrawerProps, ref: React.Ref<HTMLElemen
size = 'small',
modal = true,
separator = false,
onOpenChange,
children,
open: initialOpen = false,
defaultOpen: initialDefaultOpen = false,
...otherProps
} = props;

const [open] = useControllableState({
Expand All @@ -60,11 +33,19 @@ export const useDrawer_unstable = (props: DrawerProps, ref: React.Ref<HTMLElemen
initialState: false,
});

const { dialog, dialogSurface } = useDrawerDialogProps({
...props,
open,
modal,
});
const dialogProps = React.useMemo(() => {
return {
open,
onOpenChange,
modalType: modal ? 'modal' : 'non-modal',
children,
} as DialogProps;
}, [children, modal, onOpenChange, open]);

const dialogSurfaceProps = {
...otherProps,
children,
};

return {
components: {
Expand All @@ -76,8 +57,8 @@ export const useDrawer_unstable = (props: DrawerProps, ref: React.Ref<HTMLElemen
...props,
}),

dialog,
dialogSurface,
dialog: dialogProps,
dialogSurface: dialogSurfaceProps,

type,
open,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,39 @@ export const drawerClassNames: SlotClassNames<DrawerSlots> = {
*/
export const drawerCSSVars = {
size: '--fui-Drawer--size',
borderRadius: '--fui-Drawer--borderRadius',
};

/**
* Styles for the root slot
*/
const useStyles = makeStyles({
root: {
...shorthands.padding('16px'),
...shorthands.borderRadius(0),
...shorthands.borderRadius(`var(${drawerCSSVars.borderRadius})`),
...shorthands.border(0),
...shorthands.overflow('hidden'),

[drawerCSSVars.borderRadius]: 0,

boxSizing: 'border-box',
width: `var(${drawerCSSVars.size})`,
maxWidth: 'calc(100vw - 48px)',
height: 'auto',
display: 'flex',
flexDirection: 'column',
backgroundColor: tokens.colorNeutralBackground1,
},

overlay: {
position: 'fixed',
top: 0,
bottom: 0,
backgroundColor: tokens.colorNeutralBackground1,
},

inline: {
position: 'relative',
alignItems: 'stretch',
justifyContent: 'stretch',
},

leftDrawer: {
Expand All @@ -42,16 +57,6 @@ const useStyles = makeStyles({
left: 'auto',
},

overlay: {
position: 'fixed',
},

inline: {
position: 'relative',
alignItems: 'stretch',
justifyContent: 'stretch',
},

inlineSeparatorLeft: {
...shorthands.borderRight('1px', 'solid', tokens.colorNeutralBackground3),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import { DrawerBody } from './DrawerBody';
import { isConformant } from '../../testing/isConformant';

describe('DrawerBody', () => {
isConformant({
Component: DrawerBody,
displayName: 'DrawerBody',
});

it('renders a default state', () => {
const result = render(<DrawerBody>Default DrawerBody</DrawerBody>);
expect(result.container).toMatchInlineSnapshot(`
<div>
<div
class="fui-DrawerBody"
>
Default DrawerBody
</div>
</div>
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import { useDrawerBody_unstable } from './useDrawerBody';
import { renderDrawerBody_unstable } from './renderDrawerBody';
import { useDrawerBodyStyles_unstable } from './useDrawerBodyStyles';
import type { DrawerBodyProps } from './DrawerBody.types';
import type { ForwardRefComponent } from '@fluentui/react-utilities';

/**
* DrawerBody component - TODO: add more docs
*/
export const DrawerBody: ForwardRefComponent<DrawerBodyProps> = React.forwardRef((props, ref) => {
const state = useDrawerBody_unstable(props, ref);

useDrawerBodyStyles_unstable(state);
return renderDrawerBody_unstable(state);
});

DrawerBody.displayName = 'DrawerBody';
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';

export type DrawerBodySlots = {
root: Slot<'div'>;
};

/**
* DrawerBody Props
*/
export type DrawerBodyProps = ComponentProps<DrawerBodySlots> & {};

/**
* State used in rendering DrawerBody
*/
export type DrawerBodyState = ComponentState<DrawerBodySlots>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './DrawerBody';
export * from './DrawerBody.types';
export * from './renderDrawerBody';
export * from './useDrawerBody';
export * from './useDrawerBodyStyles';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import { getSlots } from '@fluentui/react-utilities';
import type { DrawerBodyState, DrawerBodySlots } from './DrawerBody.types';

/**
* Render the final JSX of DrawerBody
*/
export const renderDrawerBody_unstable = (state: DrawerBodyState) => {
const { slots, slotProps } = getSlots<DrawerBodySlots>(state);

return <slots.root {...slotProps.root} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from 'react';
import { getNativeElementProps } from '@fluentui/react-utilities';
import type { DrawerBodyProps, DrawerBodyState } from './DrawerBody.types';

/**
* Create the state required to render DrawerBody.
*
* The returned state can be modified with hooks such as useDrawerBodyStyles_unstable,
* before being passed to renderDrawerBody_unstable.
*
* @param props - props from this instance of DrawerBody
* @param ref - reference to root HTMLElement of DrawerBody
*/
export const useDrawerBody_unstable = (props: DrawerBodyProps, ref: React.Ref<HTMLElement>): DrawerBodyState => {
return {
components: {
root: 'div',
},

root: getNativeElementProps('div', {
ref,
...props,
}),
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { makeStyles, mergeClasses, shorthands } from '@griffel/react';
import type { DrawerBodySlots, DrawerBodyState } from './DrawerBody.types';
import type { SlotClassNames } from '@fluentui/react-utilities';
import { tokens } from '@fluentui/react-theme';

export const drawerBodyClassNames: SlotClassNames<DrawerBodySlots> = {
root: 'fui-DrawerBody',
};

/**
* Styles for the root slot
*/
const useStyles = makeStyles({
root: {
...shorthands.margin('-1px', 0),
...shorthands.padding('1px', tokens.spacingHorizontalXXL),
...shorthands.overflow('auto'),
...shorthands.flex(1),

// A "good hack" to display top and bottom borders based on the scroll position
backgroundImage: `linear-gradient(to top, ${tokens.colorNeutralBackground1}, ${tokens.colorNeutralBackground1}),
linear-gradient(to top, ${tokens.colorNeutralBackground1}, ${tokens.colorNeutralBackground1}),
linear-gradient(to top, ${tokens.colorNeutralStroke1}, ${tokens.colorNeutralBackground1}),
linear-gradient(to bottom, ${tokens.colorNeutralStroke1}, ${tokens.colorNeutralBackground1})`,
'background-position': 'bottom center, top center, bottom center, top center',
backgroundRepeat: 'no-repeat',
backgroundColor: tokens.colorNeutralBackground1,
backgroundSize: '100% 2px, 100% 2px, 100% 1px, 100% 1px',
backgroundAttachment: 'local, local, scroll, scroll',

':last-child': {
paddingBottom: `calc(${tokens.spacingHorizontalXXL} + 1px)`,
},

':first-child': {
paddingTop: `calc(${tokens.spacingHorizontalXXL} + 1px)`,
},
},
});

/**
* Apply styling to the DrawerBody slots based on the state
*/
export const useDrawerBodyStyles_unstable = (state: DrawerBodyState): DrawerBodyState => {
const styles = useStyles();

state.root.className = mergeClasses(drawerBodyClassNames.root, styles.root, state.root.className);

return state;
};
8 changes: 8 additions & 0 deletions packages/react-components/react-drawer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ export {
} from './Drawer';

export type { DrawerProps, DrawerSlots, DrawerState } from './Drawer';
export {
DrawerBody,
drawerBodyClassNames,
renderDrawerBody_unstable,
useDrawerBodyStyles_unstable,
useDrawerBody_unstable,
} from './DrawerBody';
export type { DrawerBodyProps, DrawerBodySlots, DrawerBodyState } from './DrawerBody';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Best practices

### Do

### Don't
Loading