Files
NapCatQQ/.pnpm-store/v3/files/26/2df8016717530213bf16fd068b48e8cf7a23e2b816182e12b3c09086c003690c5553e2fd5f7596e7476fe42bff86576a2870d8bb463af5d75b7fe19d38b22c
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.0 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) {
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
})
}));
}