import * as React from 'react'; import { Checkbox, ICheckboxStyles, DefaultPalette, Dropdown, IDropdownOption, Slider, Stack, IStackStyles, IStackItemStyles, IStackTokens, IStackProps, TextField, } from '@fluentui/react'; import { useBoolean } from '@fluentui/react-hooks'; import { range } from '@fluentui/example-data'; export interface IExampleOptions { numItems: number; showBoxShadow: boolean; preventOverflow: boolean; wrap: boolean; wrapperWidth: number; disableShrink: boolean; columnGap: number; rowGap: number; paddingLeft: number; paddingRight: number; paddingTop: number; paddingBottom: number; horizontalAlignment: IStackProps['horizontalAlign']; verticalAlignment: IStackProps['verticalAlign']; hideEmptyChildren: boolean; emptyChildren: string[]; } // Alignment options const horizontalAlignmentOptions: IDropdownOption[] = [ { key: 'start', text: 'Left' }, { key: 'center', text: 'Center' }, { key: 'end', text: 'Right' }, { key: 'space-around', text: 'Space around' }, { key: 'space-between', text: 'Space between' }, { key: 'space-evenly', text: 'Space evenly' }, ]; const verticalAlignmentOptions: IDropdownOption[] = [ { key: 'start', text: 'Top' }, { key: 'center', text: 'Center' }, { key: 'end', text: 'Bottom' }, ]; // Tokens definition const sectionStackTokens: IStackTokens = { childrenGap: 10 }; const configureStackTokens: IStackTokens = { childrenGap: 20 }; const shadowItemCheckboxStyles: Partial = { root: { marginRight: 10 } }; const wrapItemCheckboxStyles: Partial = { root: { marginBottom: 10 } }; const HorizontalStackConfigureExampleContent: React.FunctionComponent = props => { const { numItems, showBoxShadow, preventOverflow, wrap, wrapperWidth, disableShrink, columnGap, rowGap, paddingLeft, paddingRight, paddingTop, paddingBottom, horizontalAlignment, verticalAlignment, hideEmptyChildren, emptyChildren, } = props; // Styles definition const stackStyles: IStackStyles = { root: [ { background: DefaultPalette.themeTertiary, marginLeft: 10, marginRight: 10, minHeight: 100, width: `calc(${wrapperWidth}% - 20px)`, }, preventOverflow && { overflow: 'hidden' as 'hidden', }, ], inner: { overflow: preventOverflow ? 'hidden' : ('visible' as 'hidden' | 'visible'), }, }; const stackItemStyles: IStackItemStyles = { root: { alignItems: 'center', background: DefaultPalette.themePrimary, boxShadow: showBoxShadow ? `0px 0px 10px 5px ${DefaultPalette.themeDarker}` : '', color: DefaultPalette.white, display: 'flex', height: 50, justifyContent: 'center', width: 50, }, }; // Tokens definition const exampleStackTokens: IStackTokens = { childrenGap: rowGap + ' ' + columnGap, padding: `${paddingTop}px ${paddingRight}px ${paddingBottom}px ${paddingLeft}px`, }; return ( {range(1, numItems).map((value: number, index: number) => { if (emptyChildren.indexOf(value.toString()) !== -1) { return hideEmptyChildren ? ( ) : ( ); } return ( {value} ); })} ); }; export const HorizontalStackConfigureExample: React.FunctionComponent = () => { const [numItems, setNumItems] = React.useState(5); const [showBoxShadow, { toggle: toggleShowBoxShadow }] = useBoolean(false); const [wrap, { toggle: toggleWrap }] = useBoolean(false); const [preventOverflow, { toggle: togglePreventOverflow }] = useBoolean(false); const [disableShrink, { toggle: toggleDisableShrink }] = useBoolean(true); const [wrapperWidth, setWrapperWidth] = React.useState(100); const [columnGap, setColumnGap] = React.useState(0); const [rowGap, setRowGap] = React.useState(0); const [paddingLeft, setPaddingLeft] = React.useState(0); const [paddingRight, setPaddingRight] = React.useState(0); const [paddingTop, setPaddingTop] = React.useState(0); const [paddingBottom, setPaddingBottom] = React.useState(0); const [horizontalAlignment, setHorizontalAlignment] = React.useState('start'); const [verticalAlignment, setVerticalAlignment] = React.useState('start'); const [hideEmptyChildren, { toggle: toggleHideEmptyChildren }] = useBoolean(false); const [emptyChildren, setEmptyChildren] = React.useState([]); return ( , option: IDropdownOption): void => setHorizontalAlignment(option.key as IStackProps['horizontalAlign']) } /> , option: IDropdownOption): void => setVerticalAlignment(option.key as IStackProps['verticalAlign']) } /> , value?: string): void => { if (value === undefined) { return; } setEmptyChildren(value.replace(/,/g, '').split(' ')); }} /> ); };