react-aria
Version:
Spectrum UI components in React
76 lines (67 loc) • 3.01 kB
JavaScript
var $89b39774f3b79dbb$exports = require("../utils/mergeProps.cjs");
var $b4f85e31b7b8044c$exports = require("../interactions/useFocusWithin.cjs");
var $ixnPF$react = require("react");
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "useVisuallyHidden", function () { return $3455634180ecf75c$export$a966af930f325cab; });
$parcel$export(module.exports, "VisuallyHidden", function () { return $3455634180ecf75c$export$439d29a4e110a164; });
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
const $3455634180ecf75c$var$styles = {
border: 0,
clip: 'rect(0 0 0 0)',
clipPath: 'inset(50%)',
height: '1px',
margin: '-1px',
overflow: 'hidden',
padding: 0,
position: 'absolute',
width: '1px',
whiteSpace: 'nowrap'
};
function $3455634180ecf75c$export$a966af930f325cab(props = {}) {
let { style: style, isFocusable: isFocusable } = props;
let [isFocused, setFocused] = (0, $ixnPF$react.useState)(false);
let { focusWithinProps: focusWithinProps } = (0, $b4f85e31b7b8044c$exports.useFocusWithin)({
isDisabled: !isFocusable,
onFocusWithinChange: (val)=>setFocused(val)
});
// If focused, don't hide the element.
let combinedStyles = (0, $ixnPF$react.useMemo)(()=>{
if (isFocused) return style;
else if (style) return {
...$3455634180ecf75c$var$styles,
...style
};
else return $3455634180ecf75c$var$styles;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
isFocused
]);
return {
visuallyHiddenProps: {
...focusWithinProps,
style: combinedStyles
}
};
}
function $3455634180ecf75c$export$439d29a4e110a164(props) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
let { children: children, elementType: Element = 'div', isFocusable: isFocusable, style: style, ...otherProps } = props;
let { visuallyHiddenProps: visuallyHiddenProps } = $3455634180ecf75c$export$a966af930f325cab(props);
return /*#__PURE__*/ (0, ($parcel$interopDefault($ixnPF$react))).createElement(Element, (0, $89b39774f3b79dbb$exports.mergeProps)(otherProps, visuallyHiddenProps), children);
}
//# sourceMappingURL=VisuallyHidden.cjs.map