semantic-ui-react#Ref TypeScript Examples

The following examples show how to use semantic-ui-react#Ref. 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: index.tsx    From frontegg-react with MIT License 5 votes vote down vote up
SwitchToggle: FC<SwitchToggleProps> = (props) => {
  const ref = useRef<HTMLInputElement>(null);
  const { labels } = props;
  const { className, ...checkboxProps } = mapper(props);

  const toggle = (
    <Ref innerRef={ref}>
      <Checkbox className={classNames('fe-switch-toggle', className)} {...checkboxProps} />
    </Ref>
  );

  if (labels) {
    return (
      <div
        className={classNames('fe-switch-toggle__with_labels', {
          'fe-switch-toggle__active-left': !props.value,
          'fe-switch-toggle__active-right': props.value,
          'fe-switch-toggle__disabled': props.disabled || props.loading,
          'fe-switch-toggle__loading': props.loading,
        })}
      >
        <span
          className='fe-switch-toggle__label'
          onClick={() => {
            props.value && ref?.current?.querySelector('input')?.click();
          }}
        >
          {labels[0]}
        </span>
        {toggle}
        <span
          className='fe-switch-toggle__label'
          onClick={() => {
            !props.value && ref?.current?.querySelector('input')?.click();
          }}
        >
          {labels[1]}
        </span>
      </div>
    );
  }
  return toggle;
}