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(Help): add help button content in props #982

Merged
merged 1 commit into from
Sep 12, 2023
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
8 changes: 0 additions & 8 deletions packages/action/src/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,3 @@ $active-sort-table-th: $color-table-sorting !default;
margin-left: 2rem;
}
}

.af-more-help {
font-weight: bold;
font-family: $font-family-serif;
font-style: italic;
font-size: 1.2rem;
vertical-align: middle;
}
8 changes: 0 additions & 8 deletions packages/button/src/button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,3 @@ $active-sort-table-th: $color-table-sorting !default;
margin-left: 2rem;
}
}

.af-more-help {
font-weight: bold;
font-family: $font-family-serif;
font-style: italic;
font-size: 1.2rem;
vertical-align: middle;
}
44 changes: 28 additions & 16 deletions packages/help/src/Help.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,42 @@
import React, { ComponentPropsWithoutRef } from 'react';
import React, { ComponentPropsWithoutRef, ReactNode } from 'react';
import Popover, {
PopoverBase,
PopoverPlacements,
} from '@axa-fr/react-toolkit-popover';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

export type Props = ComponentPropsWithoutRef<typeof Popover>;
export type HelpProps = ComponentPropsWithoutRef<typeof Popover> & {
helpButtonContent?: ReactNode;
};

const Help = ({
className,
classModifier,
children,
mode = 'click',
placement = PopoverPlacements.right,
}: Props) => (
<Popover
className={className}
classModifier={classModifier}
placement={placement}
mode={mode}>
<PopoverBase.Pop>{children}</PopoverBase.Pop>
<PopoverBase.Over>
<button className="btn af-btn--circle" type="button">
<span className="af-more-help">i</span>
</button>
</PopoverBase.Over>
</Popover>
);
helpButtonContent = <span className="af-more-help">i</span>,
}: HelpProps) => {
const buttonClassName = getComponentClassName(
'btn af-btn--circle',
classModifier,
''
);

return (
<Popover
className={className}
classModifier={classModifier}
placement={placement}
mode={mode}>
<PopoverBase.Pop>{children}</PopoverBase.Pop>
<PopoverBase.Over>
<button className={buttonClassName} type="button">
{helpButtonContent}
</button>
</PopoverBase.Over>
</Popover>
);
};

export default Help;
19 changes: 19 additions & 0 deletions packages/help/src/__tests__/Help.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ import UserEvent from '@testing-library/user-event';
import Help from '../Help';

describe('Help', () => {
it('should show default help', () => {
render(<Help>Help content</Help>);

expect(screen.getByText('i')).toBeInTheDocument();
});

it('should show help passed in props', () => {
render(
<Help helpButtonContent={<i className="glyphicon glyphicon-warning" />}>
Help content
</Help>
);

expect(screen.queryByText('i')).not.toBeInTheDocument();
expect(
document.getElementsByClassName('glyphicon glyphicon-warning')
).not.toEqual([]);
});

describe('Mode click (default)', () => {
it('should show help on when clicking on i', async () => {
// Arrange
Expand Down
8 changes: 8 additions & 0 deletions packages/help/src/help-custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@
}
}
}

.af-more-help {
font-weight: bold;
font-family: $font-family-serif;
font-style: italic;
font-size: 1.2rem;
vertical-align: middle;
}
Loading