How to use @uifabric/react-hooks - 10 common examples

To help you get started, we’ve selected a few @uifabric/react-hooks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OfficeDev / office-ui-fabric-react / packages / office-ui-fabric-react / src / components / Panel / examples / Panel.HandleDismissTarget.Example.tsx View on Github external
export const PanelHandleDismissTargetExample: React.FunctionComponent = () => {
  const [isOpen, setIsOpen] = React.useState(false);

  const openPanel = useConstCallback(() => setIsOpen(true));
  const dismissPanel = useConstCallback(() => setIsOpen(false));

  const onDismiss = useConstCallback((ev?: React.SyntheticEvent) => {
    if (!ev) {
      console.log('Panel dismissed.');
      return;
    }

    // Demonstrates how to do different things depending on how which element dismissed the panel
    console.log('Close button clicked or light dismissed.');
    const srcElement = ev.nativeEvent.srcElement as Element | null;
    if (srcElement && srcElement.className.indexOf('ms-Button-icon') !== -1) {
      console.log('Close button clicked.');
    }
    if (srcElement && srcElement.className.indexOf('ms-Overlay') !== -1) {
      console.log('Light dismissed.');
    }
    dismissPanel();
  });
github OfficeDev / office-ui-fabric-react / packages / office-ui-fabric-react / src / components / Panel / examples / Panel.Footer.Example.tsx View on Github external
export const PanelFooterExample: React.FunctionComponent = () => {
  const [isOpen, setIsOpen] = React.useState(false);

  const openPanel = useConstCallback(() => setIsOpen(true));
  const dismissPanel = useConstCallback(() => setIsOpen(false));

  // This panel doesn't actually save anything; the buttons are just an example of what
  // someone might want to render in a panel footer.
  const onRenderFooterContent = useConstCallback(() => (
    <div>
      
        Save
      
      Cancel
    </div>
  ));

  return (
    <div>
      </div>
github OfficeDev / office-ui-fabric-react / packages / office-ui-fabric-react / src / components / Panel / examples / Panel.LightDismissCustom.Example.tsx View on Github external
export const PanelLightDismissCustomExample: React.FunctionComponent = () =&gt; {
  const [isPanelOpen, setIsPanelOpen] = React.useState(false);
  const [isDialogVisible, setIsDialogVisible] = React.useState(false);

  const openPanel = useConstCallback(() =&gt; setIsPanelOpen(true));
  const dismissPanel = useConstCallback(() =&gt; setIsPanelOpen(false));
  const showDialog = useConstCallback(() =&gt; setIsDialogVisible(true));
  const hideDialog = useConstCallback(ev =&gt; {
    ev.preventDefault();
    setIsDialogVisible(false);
  });
  const hideDialogAndPanel = useConstCallback(() =&gt; {
    setIsPanelOpen(false);
    setIsDialogVisible(false);
  });

  return (
    <div>
      {explanation}
      <br>
      <br>
      
      </div>
github OfficeDev / office-ui-fabric-react / packages / office-ui-fabric-react / src / components / Panel / examples / Panel.Controlled.Example.tsx View on Github external
export const PanelControlledExample: React.FunctionComponent = () =&gt; {
  const [isOpen, setIsOpen] = React.useState(false);

  const openPanel = useConstCallback(() =&gt; setIsOpen(true));
  const dismissPanel = useConstCallback(() =&gt; setIsOpen(false));

  return (
    <div>
      This panel can only be closed by clicking a button inside the panel content. (Don't use this behavior unless absolutely necessary.)
      <br>
      <br>
      
      
        <p>This panel can only be closed by clicking the button below.</p></div>
github OfficeDev / office-ui-fabric-react / packages / office-ui-fabric-react / src / components / Panel / examples / Panel.Navigation.Example.tsx View on Github external
export const PanelNavigationExample: React.FunctionComponent = () =&gt; {
  const [isOpen, setIsOpen] = React.useState(false);

  const openPanel = useConstCallback(() =&gt; setIsOpen(true));
  const dismissPanel = useConstCallback(() =&gt; setIsOpen(false));

  const onRenderNavigationContent: IRenderFunction = useConstCallback((props, defaultRender) =&gt; (
    &lt;&gt;
      
      {// This custom navigation still renders the close button (defaultRender).
      // If you don't use defaultRender, be sure to provide some other way to close the panel.
      defaultRender!(props)}
    
  ));

  return (
    <div>
      {explanation}
      <br>
      <br>
      </div>
github OfficeDev / office-ui-fabric-react / packages / office-ui-fabric-react / src / components / Tooltip / examples / Tooltip.Display.Example.tsx View on Github external
export const TooltipDisplayExample: React.FunctionComponent = () =&gt; {
  // Use useId() to ensure that the ID is unique on the page.
  // (It's also okay to use a plain string and manually ensure uniqueness.)
  const tooltip1Id = useId('tooltip1');
  const tooltip2Id = useId('tooltip2');

  return (
    <div>
      In some cases when a TooltipHost is wrapping <code>inline-block</code> or <code>inline</code> elements, the positioning of the Tooltip
      may be off. In these cases, it's recommended to set the TooltipHost's <code>display</code> property to <code>inline-block</code>, as
      in the following example.
      <br>
      <br>
      
        <button aria-describedby="{tooltip1Id}" style="{buttonStyle}">
          Hover for incorrect positioning
        </button>
      {' '}
      </div>
github OfficeDev / office-ui-fabric-react / packages / office-ui-fabric-react / src / components / Tooltip / examples / Tooltip.Custom.Example.tsx View on Github external
export const TooltipCustomExample: React.FunctionComponent = () =&gt; {
  // Use useId() to ensure that the ID is unique on the page.
  // (It's also okay to use a plain string and manually ensure uniqueness.)
  const tooltipId = useId('tooltip');

  return (
    
      
    
  );
};
github OfficeDev / office-ui-fabric-react / packages / office-ui-fabric-react / src / components / Tooltip / examples / Tooltip.Display.Example.tsx View on Github external
export const TooltipDisplayExample: React.FunctionComponent = () =&gt; {
  // Use useId() to ensure that the ID is unique on the page.
  // (It's also okay to use a plain string and manually ensure uniqueness.)
  const tooltip1Id = useId('tooltip1');
  const tooltip2Id = useId('tooltip2');

  return (
    <div>
      In some cases when a TooltipHost is wrapping <code>inline-block</code> or <code>inline</code> elements, the positioning of the Tooltip
      may be off. In these cases, it's recommended to set the TooltipHost's <code>display</code> property to <code>inline-block</code>, as
      in the following example.
      <br>
      <br>
      
        <button aria-describedby="{tooltip1Id}" style="{buttonStyle}">
          Hover for incorrect positioning
        </button>
      {' '}
      </div>
github OfficeDev / office-ui-fabric-react / packages / office-ui-fabric-react / src / components / Tooltip / examples / Tooltip.Basic.Example.tsx View on Github external
export const TooltipBasicExample: React.FunctionComponent = () =&gt; {
  // Use useId() to ensure that the ID is unique on the page.
  // (It's also okay to use a plain string and manually ensure uniqueness.)
  const tooltipId = useId('tooltip');

  return (
    <div>
      
        Hover over me
      
    </div>
  );
};
github OfficeDev / office-ui-fabric-react / packages / office-ui-fabric-react / src / components / Tooltip / examples / Tooltip.Interactive.Example.tsx View on Github external
export const TooltipInteractiveExample: React.FunctionComponent = () =&gt; {
  // Use useId() to ensure that the ID is unique on the page.
  // (It's also okay to use a plain string and manually ensure uniqueness.)
  const tooltipId = useId('tooltip');

  return (
    <div>
      
        Interact with my tooltip
      
    </div>
  );
};

@uifabric/react-hooks

Fluent UI React hooks.

MIT
Latest version published 2 years ago

Package Health Score

75 / 100
Full package analysis

Similar packages