Files
NapCatQQ/.pnpm-store/v3/files/51/b0dbf2b24f99c9193ccbd069b31bd4e9ac5878c05b4fe6fb6839b274fe7394ad0b581da764b3ac5856cd7b2e06d2c3d4a8d8dd669deb4120624cb530c7b748
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

56 lines
2.1 KiB
Plaintext

/*
* 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.
*/
import clsx from 'clsx';
import {mergeProps} from '@react-aria/utils';
import React, {ReactElement} from 'react';
import {useFocusRing} from './useFocusRing';
export interface FocusRingProps {
/** Child element to apply CSS classes to. */
children: ReactElement,
/** CSS class to apply when the element is focused. */
focusClass?: string,
/** CSS class to apply when the element has keyboard focus. */
focusRingClass?: string,
/**
* Whether to show the focus ring when something
* inside the container element has focus (true), or
* only if the container itself has focus (false).
* @default false
*/
within?: boolean,
/** Whether the element is a text input. */
isTextInput?: boolean,
/** Whether the element will be auto focused. */
autoFocus?: boolean
}
/**
* A utility component that applies a CSS class when an element has keyboard focus.
* Focus rings are visible only when the user is interacting with a keyboard,
* not with a mouse, touch, or other input methods.
*/
export function FocusRing(props: FocusRingProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>> {
let {children, focusClass, focusRingClass} = props;
let {isFocused, isFocusVisible, focusProps} = useFocusRing(props);
let child = React.Children.only(children);
return React.cloneElement(child, mergeProps(child.props as any, {
...focusProps,
className: clsx({
[focusClass || '']: isFocused,
[focusRingClass || '']: isFocusVisible
})
}));
}