[components] TopButton 수정
Detail Notes : 1. props 추가, onTopButtonBlur, onTopButtonClick, onTopButtonFocus
This commit is contained in:
@@ -1,25 +1,47 @@
|
|||||||
import React, {
|
import React, { memo, useCallback, useState } from "react";
|
||||||
memo,
|
|
||||||
useCallback,
|
|
||||||
} from 'react';
|
|
||||||
|
|
||||||
import Spotlight from '@enact/spotlight';
|
import Spotlight from "@enact/spotlight";
|
||||||
import Spottable from '@enact/spotlight/Spottable';
|
import Spottable from "@enact/spotlight/Spottable";
|
||||||
|
|
||||||
import css from './TopButton.module.less';
|
import css from "./TopButton.module.less";
|
||||||
|
|
||||||
const SpottableComponent = Spottable("button");
|
const SpottableComponent = Spottable("button");
|
||||||
|
|
||||||
export default memo(function TopButton({ className, targetId, ...rest }) {
|
export default memo(function TopButton({
|
||||||
|
className,
|
||||||
|
onTopButtonBlur,
|
||||||
|
onTopButtonClick,
|
||||||
|
onTopButtonFocus,
|
||||||
|
targetId,
|
||||||
|
...rest
|
||||||
|
}) {
|
||||||
|
const [_, setIsFocused] = useState(false);
|
||||||
|
|
||||||
|
const handleBlur = useCallback(() => {
|
||||||
|
setIsFocused(false);
|
||||||
|
onTopButtonBlur && onTopButtonBlur();
|
||||||
|
}, [onTopButtonBlur]);
|
||||||
|
|
||||||
const handleClick = useCallback(() => {
|
const handleClick = useCallback(() => {
|
||||||
targetId && Spotlight.focus(targetId);
|
if (targetId) {
|
||||||
}, [targetId]);
|
Spotlight.focus(targetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
onTopButtonClick && onTopButtonClick();
|
||||||
|
}, [onTopButtonClick, targetId]);
|
||||||
|
|
||||||
|
const handleFocus = useCallback(() => {
|
||||||
|
setIsFocused(true);
|
||||||
|
onTopButtonFocus && onTopButtonFocus();
|
||||||
|
}, [onTopButtonFocus]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={css.container}>
|
<div className={css.container}>
|
||||||
<SpottableComponent
|
<SpottableComponent
|
||||||
className={className && className}
|
className={className && className}
|
||||||
|
onBlur={handleBlur}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
|
onFocus={handleFocus}
|
||||||
{...rest}
|
{...rest}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user