Skip to content

Commit

Permalink
refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
gitdallas committed Oct 19, 2023
1 parent fed5a90 commit 692562f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
20 changes: 9 additions & 11 deletions packages/react-core/src/components/ClipboardCopy/ClipboardCopy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ClipboardCopyToggle } from './ClipboardCopyToggle';
import { ClipboardCopyExpanded } from './ClipboardCopyExpanded';
import { getOUIAProps, OUIAProps } from '../../helpers';

export const clipboardCopyFunc = (event: React.ClipboardEvent<HTMLDivElement>, text?: React.ReactNode) => {
export const clipboardCopyFunc = (event: React.ClipboardEvent<HTMLDivElement>, text?: string) => {
navigator.clipboard.writeText(text.toString());
};

Expand All @@ -21,7 +21,7 @@ export enum ClipboardCopyVariant {
}

export interface ClipboardCopyState {
text: string | number;
text: string;
expanded: boolean;
copied: boolean;
}
Expand Down Expand Up @@ -70,9 +70,9 @@ export interface ClipboardCopyProps extends Omit<React.HTMLProps<HTMLDivElement>
/** Delay in ms before the tooltip appears. */
entryDelay?: number;
/** A function that is triggered on clicking the copy button. */
onCopy?: (event: React.ClipboardEvent<HTMLDivElement>, text?: React.ReactNode) => void;
onCopy?: (event: React.ClipboardEvent<HTMLDivElement>, text?: string) => void;
/** A function that is triggered on changing the text. */
onChange?: (event: React.FormEvent, text?: string | number) => void;
onChange?: (event: React.FormEvent, text?: string) => void;
/** The text which is copied. */
children: string;
/** Additional actions for inline clipboard copy. Should be wrapped with ClipboardCopyAction. */
Expand All @@ -89,9 +89,7 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
constructor(props: ClipboardCopyProps) {
super(props);
this.state = {
text: Array.isArray(this.props.children)
? this.props.children.join('')
: (this.props.children as string | number),
text: Array.isArray(this.props.children) ? this.props.children.join('') : (this.props.children as string),
expanded: this.props.isExpanded,
copied: false
};
Expand Down Expand Up @@ -119,7 +117,7 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
// eslint-disable-next-line @typescript-eslint/no-unused-vars
componentDidUpdate = (prevProps: ClipboardCopyProps, prevState: ClipboardCopyState) => {
if (prevProps.children !== this.props.children) {
this.setState({ text: this.props.children as string | number });
this.setState({ text: this.props.children as string });
}
};

Expand All @@ -136,7 +134,7 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
}));
};

updateText = (event: React.FormEvent, text: string | number) => {
updateText = (event: React.FormEvent, text: string) => {
this.setState({ text });
this.props.onChange(event, text);
};
Expand Down Expand Up @@ -239,7 +237,7 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
<TextInput
readOnlyVariant={isReadOnly || this.state.expanded ? 'default' : undefined}
onChange={this.updateText}
value={this.state.text as string | number}
value={this.state.text}
id={`text-input-${id}`}
aria-label={textAriaLabel}
{...(isCode && { dir: 'ltr' })}
Expand Down Expand Up @@ -268,7 +266,7 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
id={`content-${id}`}
onChange={this.updateText}
>
{this.state.text as string}
{this.state.text}
</ClipboardCopyExpanded>
)}
</React.Fragment>
Expand Down
16 changes: 3 additions & 13 deletions packages/react-core/src/components/Wizard/Wizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface WizardProps extends React.HTMLProps<HTMLDivElement> {
footer?: WizardFooterType;
/** Wizard navigation */
nav?: WizardNavType;
/** Aria-label for the Nav */
navAriaLabel?: string;
/** The initial index the wizard is to start on (1 or higher). Defaults to 1. */
startIndex?: number;
/** Additional classes spread to the wizard */
Expand Down Expand Up @@ -65,7 +63,6 @@ export const Wizard = ({
className,
header,
nav,
navAriaLabel,
startIndex = 1,
isVisitRequired = false,
isProgressive = false,
Expand Down Expand Up @@ -179,23 +176,17 @@ export const Wizard = ({
{...wrapperProps}
>
{header}
<WizardInternal
nav={nav}
navAriaLabel={navAriaLabel}
isVisitRequired={isVisitRequired}
isProgressive={isProgressive}
/>
<WizardInternal nav={nav} isVisitRequired={isVisitRequired} isProgressive={isProgressive} />
</div>
</WizardContextProvider>
);
};

const WizardInternal = ({
nav,
navAriaLabel,
isVisitRequired,
isProgressive
}: Pick<WizardProps, 'nav' | 'navAriaLabel' | 'isVisitRequired' | 'isProgressive'>) => {
}: Pick<WizardProps, 'nav' | 'isVisitRequired' | 'isProgressive'>) => {
const { activeStep, steps, footer, goToStepByIndex } = useWizardContext();
const [isNavExpanded, setIsNavExpanded] = React.useState(false);

Expand All @@ -207,13 +198,12 @@ const WizardInternal = ({
return (
<WizardNavInternal
nav={nav}
navAriaLabel={navAriaLabel}
isNavExpanded={isNavExpanded}
isVisitRequired={isVisitRequired}
isProgressive={isProgressive}
/>
);
}, [activeStep, isVisitRequired, isProgressive, goToStepByIndex, isNavExpanded, nav, navAriaLabel, steps]);
}, [activeStep, isVisitRequired, isProgressive, goToStepByIndex, isNavExpanded, nav, steps]);

return (
<WizardToggle
Expand Down

0 comments on commit 692562f

Please sign in to comment.