Skip to content

Commit

Permalink
codestyle improvmeents
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-kot committed Sep 12, 2024
1 parent 0a67544 commit d3b0aba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
17 changes: 10 additions & 7 deletions src/alert/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const InternalAlert = React.forwardRef(

const { discoveredActions, headerRef: headerRefAction, contentRef: contentRefAction } = useDiscoveredAction(type);
const {
hasReplacementHeader,
hasReplacementContent,
headerReplacementType,
contentReplacementType,
headerRef: headerRefContent,
contentRef: contentRefContent,
replacementHeaderRef,
Expand All @@ -85,7 +85,7 @@ const InternalAlert = React.forwardRef(
const isRefresh = useVisualRefresh();
const size = isRefresh
? 'normal'
: hasReplacementHeader !== 'remove' && header && hasReplacementContent !== 'remove' && children
: headerReplacementType !== 'remove' && header && contentReplacementType !== 'remove' && children
? 'big'
: 'normal';

Expand Down Expand Up @@ -123,7 +123,7 @@ const InternalAlert = React.forwardRef(
<div
className={clsx(
header && styles.header,
hasReplacementHeader !== 'original' ? styles.hidden : analyticsSelectors.header
headerReplacementType !== 'original' ? styles.hidden : analyticsSelectors.header
)}
ref={headerRef}
>
Expand All @@ -132,18 +132,21 @@ const InternalAlert = React.forwardRef(
<div
className={clsx(
styles['header-replacement'],
hasReplacementHeader !== true ? styles.hidden : analyticsSelectors.header
headerReplacementType !== 'replaced' ? styles.hidden : analyticsSelectors.header
)}
ref={replacementHeaderRef}
></div>
<div
className={clsx(styles.content, hasReplacementContent !== 'original' && styles.hidden)}
className={clsx(styles.content, contentReplacementType !== 'original' && styles.hidden)}
ref={contentRef}
>
{children}
</div>
<div
className={clsx(styles['content-replacement'], hasReplacementContent !== true && styles.hidden)}
className={clsx(
styles['content-replacement'],
contentReplacementType !== 'replaced' && styles.hidden
)}
ref={replacementContentRef}
></div>
</div>
Expand Down
12 changes: 6 additions & 6 deletions src/flashbar/flash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ export const Flash = React.forwardRef(
const contentRefObject = useRef<HTMLDivElement>(null);
const { discoveredActions, headerRef: headerRefAction, contentRef: contentRefAction } = useDiscoveredAction(type);
const {
hasReplacementHeader,
hasReplacementContent,
headerReplacementType,
contentReplacementType,
headerRef: headerRefContent,
contentRef: contentRefContent,
replacementHeaderRef,
Expand Down Expand Up @@ -181,23 +181,23 @@ export const Flash = React.forwardRef(
</div>
<div className={clsx(styles['flash-message'], styles['flash-text'])}>
<div
className={clsx(styles['flash-header'], hasReplacementHeader !== 'original' && styles.hidden)}
className={clsx(styles['flash-header'], headerReplacementType !== 'original' && styles.hidden)}
ref={headerRef}
>
{header}
</div>
<div
className={clsx(styles['header-replacement'], hasReplacementHeader !== true && styles.hidden)}
className={clsx(styles['header-replacement'], headerReplacementType !== 'replaced' && styles.hidden)}
ref={replacementHeaderRef}
></div>
<div
className={clsx(styles['flash-content'], hasReplacementContent !== 'original' && styles.hidden)}
className={clsx(styles['flash-content'], contentReplacementType !== 'original' && styles.hidden)}
ref={contentRef}
>
{content}
</div>
<div
className={clsx(styles['content-replacement'], hasReplacementContent !== true && styles.hidden)}
className={clsx(styles['content-replacement'], contentReplacementType !== 'replaced' && styles.hidden)}
ref={replacementContentRef}
></div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/internal/plugins/controllers/alert-flash-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface AlertFlashContentContext {
contentRef: RefShim<HTMLElement>;
}

export type ReplacementTypeSafe = 'original' | 'remove' | true;
export type ReplacementType = 'original' | 'remove' | 'replaced';

export interface ReplacementApi {
hideHeader(): void;
Expand Down
14 changes: 7 additions & 7 deletions src/internal/plugins/helpers/use-discovered-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ReactNode, useEffect, useRef, useState } from 'react';
import {
AlertFlashContentController,
AlertFlashContentResult,
ReplacementTypeSafe,
ReplacementType,
} from '../controllers/alert-flash-content';

export function createUseDiscoveredContent(
Expand All @@ -25,8 +25,8 @@ export function createUseDiscoveredContent(
const contentRef = useRef<HTMLDivElement>(null);
const replacementHeaderRef = useRef<HTMLDivElement>(null);
const replacementContentRef = useRef<HTMLDivElement>(null);
const [foundHeaderReplacement, setFoundHeaderReplacement] = useState<ReplacementTypeSafe>('original');
const [foundContentReplacement, setFoundContentReplacement] = useState<ReplacementTypeSafe>('original');
const [headerReplacementType, setFoundHeaderReplacement] = useState<ReplacementType>('original');
const [contentReplacementType, setFoundContentReplacement] = useState<ReplacementType>('original');
const mountedProvider = useRef<AlertFlashContentResult | undefined>();

useEffect(() => {
Expand Down Expand Up @@ -59,7 +59,7 @@ export function createUseDiscoveredContent(
replaceHeader(replacer: (container: HTMLElement) => void) {
if (checkMounted('replaceHeader')) {
replacer(replacementHeaderRef.current!);
setFoundHeaderReplacement(true);
setFoundHeaderReplacement('replaced');
}
},
hideContent() {
Expand All @@ -75,7 +75,7 @@ export function createUseDiscoveredContent(
replaceContent(replacer: (container: HTMLElement) => void) {
if (checkMounted('replaceContent')) {
replacer(replacementContentRef.current!);
setFoundContentReplacement(true);
setFoundContentReplacement('replaced');
}
},
});
Expand All @@ -95,8 +95,8 @@ export function createUseDiscoveredContent(
}, [type, header, children]);

return {
hasReplacementHeader: foundHeaderReplacement,
hasReplacementContent: foundContentReplacement,
headerReplacementType,
contentReplacementType,
headerRef: headerRef as React.Ref<HTMLDivElement>,
replacementHeaderRef: replacementHeaderRef as React.Ref<HTMLDivElement>,
contentRef: contentRef as React.Ref<HTMLDivElement>,
Expand Down

0 comments on commit d3b0aba

Please sign in to comment.