Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Button): added inline link progress support to demos #8172

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,22 @@ describe('Button', () => {
expect(asFragment()).toMatchSnapshot();
});

test('isLoading inline link', () => {
const { asFragment } = render(
<Button variant="link" isInline isLoading aria-label="Loading" spinnerAriaValueText="Loading">
Loading Button
</Button>
);
expect(asFragment()).toMatchSnapshot();
});

test('isLoading icon only', () => {
const { asFragment } = render(
<Button variant="plain" isLoading aria-label="Upload" spinnerAriaValueText="Loading" icon={<div>ICON</div>} />
);
expect(asFragment()).toMatchSnapshot();
});

test('allows passing in a string as the component', () => {
const component = 'a';
render(<Button component={component}>anchor button</Button>);
Expand Down Expand Up @@ -130,11 +146,4 @@ describe('Button', () => {
render(<Button tabIndex={0}>TabIndex 0 Button</Button>);
expect(screen.getByRole('button')).toHaveAttribute('tabindex', '0');
});

test('isLoading icon only', () => {
const { asFragment } = render(
<Button variant="plain" isLoading aria-label="Upload" spinnerAriaValueText="Loading" icon={<div>ICON</div>} />
);
expect(asFragment()).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,42 @@ exports[`Button isLoading icon only 1`] = `
</DocumentFragment>
`;

exports[`Button isLoading inline link 1`] = `
<DocumentFragment>
<button
aria-disabled="false"
aria-label="Loading"
class="pf-c-button pf-m-link pf-m-inline pf-m-progress pf-m-in-progress"
data-ouia-component-id="OUIA-Generated-Button-link-5"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
>
<span
class="pf-c-button__progress"
>
<span
aria-label="Contents"
aria-valuetext="Loading"
class="pf-c-spinner pf-m-md"
role="progressbar"
>
<span
class="pf-c-spinner__clipper"
/>
<span
class="pf-c-spinner__lead-ball"
/>
<span
class="pf-c-spinner__tail-ball"
/>
</span>
</span>
Loading Button
</button>
</DocumentFragment>
`;

exports[`Button isSmall 1`] = `
<DocumentFragment>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface LoadingPropsType {
export const ButtonProgress: React.FunctionComponent = () => {
const [isPrimaryLoading, setIsPrimaryLoading] = React.useState<boolean>(true);
const [isSecondaryLoading, setIsSecondaryLoading] = React.useState<boolean>(true);
const [isInlineLoading, setIsInlineLoading] = React.useState<boolean>(true);
const [isUploading, setIsUploading] = React.useState<boolean>(false);

const primaryLoadingProps = {} as LoadingPropsType;
Expand All @@ -24,6 +25,11 @@ export const ButtonProgress: React.FunctionComponent = () => {
secondaryLoadingProps.spinnerAriaLabel = 'Content being loaded';
secondaryLoadingProps.isLoading = isSecondaryLoading;

const inlineLoadingProps = {} as LoadingPropsType;
inlineLoadingProps.spinnerAriaValueText = 'Loading';
inlineLoadingProps.spinnerAriaLabel = 'Content being loaded';
inlineLoadingProps.isLoading = isInlineLoading;

const uploadingProps = {} as LoadingPropsType;
uploadingProps.spinnerAriaValueText = 'Loading';
uploadingProps.spinnerAriaLabel = 'Uploading data';
Expand All @@ -37,18 +43,25 @@ export const ButtonProgress: React.FunctionComponent = () => {
onClick={() => setIsPrimaryLoading(!isPrimaryLoading)}
{...primaryLoadingProps}
>
{isPrimaryLoading ? 'Pause loading logs' : 'Resume loading logs'}
{isPrimaryLoading ? 'Click to stop loading' : 'Click to start loading'}
</Button>{' '}
<Button variant="secondary" onClick={() => setIsSecondaryLoading(!isSecondaryLoading)} {...secondaryLoadingProps}>
{isSecondaryLoading ? 'Click to stop loading' : 'Click to start loading'}
</Button>{' '}
<br />
<br />
<Button
variant="plain"
{...(!isUploading && { 'aria-label': 'Upload' })}
onClick={() => setIsUploading(!isUploading)}
icon={<UploadIcon />}
{...uploadingProps}
/>
/>{' '}
<br />
<br />
<Button variant="link" isInline onClick={() => setIsInlineLoading(!isInlineLoading)} {...inlineLoadingProps}>
{isInlineLoading ? 'Pause loading logs' : 'Resume loading logs'}
</Button>{' '}
</React.Fragment>
);
};