office-ui-fabric-react#TeachingBubble TypeScript Examples

The following examples show how to use office-ui-fabric-react#TeachingBubble. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TeachingBubbleWrapper.tsx    From hypertrons-crx with Apache License 2.0 5 votes vote down vote up
TeachingBubbleWrapper: React.FC<TeachingBubbleProps> = ({ target }) => {
  const [metaData, setMetaData] = useState(new MetaData());
  const [inited, setInited] = useState(false);
  const [settings, setSettings] = useState(new Settings());
  const [teachingBubbleVisible, { toggle: toggleTeachingBubbleVisible }] =
    useBoolean(true);

  useEffect(() => {
    const initSettings = async () => {
      const temp = await loadSettings();
      setSettings(temp);
      setInited(true);
    };
    if (!inited) {
      initSettings();
    }
  }, [settings]);

  useEffect(() => {
    const initMetaData = async () => {
      const temp = await loadMetaData();
      setMetaData(temp);
    };
    initMetaData();
  }, []);

  const disableButtonProps: IButtonProps = React.useMemo(
    () => ({
      children: getMessageByLocale('global_btn_disable', settings.locale),
      onClick: async () => {
        metaData.showTeachingBubble = false;
        await chromeSet('meta_data', metaData.toJson());
        toggleTeachingBubbleVisible();
      },
    }),
    [metaData, settings.locale, toggleTeachingBubbleVisible]
  );

  const confirmButtonProps: IButtonProps = React.useMemo(
    () => ({
      children: getMessageByLocale('global_btn_ok', settings.locale),
      onClick: toggleTeachingBubbleVisible,
    }),
    [settings.locale, toggleTeachingBubbleVisible]
  );

  return (
    <div>
      {teachingBubbleVisible && inited && metaData.showTeachingBubble && (
        <TeachingBubble
          target={target}
          primaryButtonProps={disableButtonProps}
          secondaryButtonProps={confirmButtonProps}
          onDismiss={toggleTeachingBubbleVisible}
          headline={getMessageByLocale(
            'teachingBubble_text_headline',
            settings.locale
          )}
        >
          {getMessageByLocale('teachingBubble_text_content', settings.locale)}
        </TeachingBubble>
      )}
    </div>
  );
}