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

add button type for Dropdown and custom props for Modal custom footer #34

Merged
merged 4 commits into from
Aug 16, 2024
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
1 change: 1 addition & 0 deletions src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export const Dropdown: FC<DropdownProps> = ({
onKeyDown: handleToggleButtonKeyDown,
ref: refs.setReference,
})}
type="button"
>
{icon && <span className={cx('icon')}>{icon}</span>}
<span className={cx('value', { placeholder: !value })}>{getDisplayedValue()}</span>
Expand Down
1 change: 1 addition & 0 deletions src/components/modal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Default width - 480px, height 100%
- **size**: _string_, optional, default = "default"
- **onClose**: _function_, optional, default = () => {}
- **description**: _node_, optional, default = null
- **createFooter**: _function_, optional, default = null

### Variants

Expand Down
4 changes: 4 additions & 0 deletions src/components/modal/modal.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ $WIDTH-LARGE: 720px;
font-weight: $fw-regular;
@include font-scale();
color: var(--rp-ui-base-almost-black);

&.scrollable{
width: calc(100% - 34px);
}
}

.size-default {
Expand Down
6 changes: 3 additions & 3 deletions src/components/modal/modal.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Modal } from './modal';
import { FC, useState } from 'react';
import { useState } from 'react';
import { Button } from '@components/button';

const meta: Meta<typeof Modal> = {
Expand Down Expand Up @@ -47,7 +47,7 @@ export const WithSteps: Story = {
const [step, setStep] = useState<number>(1);
const buttonStyle = { minWidth: 'fit-content' };

const CustomFooter: FC<{ closeHandler: () => void }> = ({ closeHandler }) => {
const createFooter = (closeHandler: () => void) => {
return (
<div
style={{
Expand All @@ -73,7 +73,7 @@ export const WithSteps: Story = {
};

return (
<Modal {...args} title={'Modal with steps'} CustomFooter={CustomFooter}>
<Modal {...args} title={'Modal with steps'} createFooter={createFooter}>
content for step {step}
</Modal>
);
Expand Down
16 changes: 10 additions & 6 deletions src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
cancelButton?: ButtonProps;
scrollable?: boolean;
withoutFooter?: boolean;
CustomFooter?: FC<{ closeHandler: () => void }>;
createFooter?: (closeHandler: () => void) => ReactNode;
description?: ReactNode;
}

Expand All @@ -53,7 +53,7 @@
allowCloseOutside = true,
scrollable = false,
withoutFooter = false,
CustomFooter = null,
createFooter = null,
description = null,
}) => {
const [isShown, setShown] = useState(false);
Expand Down Expand Up @@ -104,7 +104,7 @@
document.addEventListener('keydown', onKeydown, false);

return () => document.removeEventListener('keydown', onKeydown, false);
}, []);

Check warning on line 107 in src/components/modal/modal.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useEffect has a missing dependency: 'onKeydown'. Either include it or remove the dependency array

useOnClickOutside(modalRef, allowCloseOutside ? closeModal : undefined);

Expand All @@ -126,8 +126,12 @@
<ModalHeader title={title} onClose={closeModal} withDescription={!!description} />
{scrollable ? (
<Scrollbars autoHeight autoHeightMax={getContentMaxHeight()} hideTracksWhenNotNeeded>
{description && <span className={cx('description')}>{description}</span>}
<ModalContent>{children}</ModalContent>
{description && (
<span className={cx('description', { scrollable: scrollable })}>
{description}
</span>
)}
<ModalContent scrollable>{children}</ModalContent>
</Scrollbars>
) : (
<>
Expand All @@ -136,8 +140,8 @@
</>
)}
{!withoutFooter &&
(CustomFooter ? (
<CustomFooter closeHandler={closeModal} />
(createFooter ? (
createFooter(closeModal)
) : (
<ModalFooter
size={size}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
@import 'src/assets/styles/mixins/font-scale';

.modal-content {
width: calc(100% - 34px);
width: 100%;
font-family: var(--rp-ui-base-font-family);
font-weight: $fw-regular;
@include font-scale();
color: var(--rp-ui-color-text);
white-space: pre-line;
word-break: break-word;
padding: 0 0 16px;

&.scrollable {
width: calc(100% - 34px);
}
}
5 changes: 3 additions & 2 deletions src/components/modal/modalContent/modalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import styles from './modalContent.module.scss';
const cx = classNames.bind(styles);

interface ModalContentProps {
scrollable?: boolean;
children?: ReactNode;
}

export const ModalContent: FC<ModalContentProps> = ({ children }) => (
<div className={cx('modal-content')}>{children}</div>
export const ModalContent: FC<ModalContentProps> = ({ scrollable = false, children }) => (
<div className={cx('modal-content', { scrollable: scrollable })}>{children}</div>
);
Loading