UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

41 lines (37 loc) 1.93 kB
import styled from 'styled-components'; import sx from '../sx.js'; import { toggleStyledComponent } from '../internal/utils/toggleStyledComponent.js'; import { clsx } from 'clsx'; import '../FeatureFlags/FeatureFlags.js'; import { useFeatureFlag } from '../FeatureFlags/useFeatureFlag.js'; import '../FeatureFlags/DefaultFeatureFlags.js'; import React from 'react'; import classes from './VisuallyHidden.module.css.js'; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_ga'; /** * Provides a component that implements the "visually hidden" technique. This is * analagous to the common `sr-only` class. Children that are rendered inside * this component will not be visible but will be available to screen readers. * * Note: if this component, or a descendant, has focus then this component will * no longer be visually hidden. * * @see https://www.scottohara.me/blog/2023/03/21/visually-hidden-hack.html */ const StyledVisuallyHidden = toggleStyledComponent(CSS_MODULES_FEATURE_FLAG, 'span', styled.span.withConfig({ displayName: "VisuallyHidden__StyledVisuallyHidden", componentId: "sc-1rhpuyf-0" })(["&:not(:focus):not(:active):not(:focus-within){clip-path:inset(50%);height:1px;overflow:hidden;position:absolute;white-space:nowrap;width:1px;}", ""], sx)); const VisuallyHidden = ({ className, children, ...rest }) => { const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG); return /*#__PURE__*/React.createElement(StyledVisuallyHidden, _extends({ className: clsx(className, enabled && classes.VisuallyHidden) }, rest), children); }; VisuallyHidden.displayName = "VisuallyHidden"; export { VisuallyHidden };