@@ -3,34 +3,38 @@ import * as React from 'react';
33
44export type ClosableConfig = {
55 closeIcon ?: React . ReactNode ;
6+ disabled ?: boolean ;
67 onClose ?: VoidFunction ;
78} & React . AriaAttributes ;
89
910export type ClosableType = boolean | ClosableConfig | null | undefined ;
1011
11- export type MergedClosableConfig = Omit < ClosableConfig , 'closeIcon' > & {
12- closeIcon : React . ReactNode ;
13- } ;
14-
15- const EMPTY_CLOSABLE : ClosableConfig = { } ;
16-
17- function normalizeClosable ( closable ?: ClosableType ) : ClosableConfig {
18- if ( typeof closable === 'object' && closable !== null ) {
19- return closable ;
20- }
21-
22- return EMPTY_CLOSABLE ;
23- }
12+ export type ParsedClosableConfig = ClosableConfig &
13+ Required < Pick < ClosableConfig , 'closeIcon' | 'disabled' > > ;
2414
2515export default function useClosable (
2616 closable ?: ClosableType ,
27- ) : [ boolean , MergedClosableConfig , ReturnType < typeof pickAttrs > ] {
28- const closableObj = React . useMemo ( ( ) => normalizeClosable ( closable ) , [ closable ] ) ;
29-
30- const closableConfig = React . useMemo < MergedClosableConfig > (
17+ ) : [ boolean , ParsedClosableConfig , ReturnType < typeof pickAttrs > ] {
18+ const closableObj = React . useMemo ( ( ) => {
19+ if ( closable === false ) {
20+ return {
21+ closeIcon : null ,
22+ disabled : true ,
23+ } ;
24+ }
25+
26+ if ( typeof closable === 'object' && closable !== null ) {
27+ return closable ;
28+ }
29+
30+ return { } ;
31+ } , [ closable ] ) ;
32+
33+ const closableConfig = React . useMemo < ParsedClosableConfig > (
3134 ( ) => ( {
3235 ...closableObj ,
33- closeIcon : closableObj . closeIcon ?? 'x' ,
36+ closeIcon : closableObj . closeIcon ?? '×' ,
37+ disabled : closableObj . disabled ?? false ,
3438 } ) ,
3539 [ closableObj ] ,
3640 ) ;
0 commit comments