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(select): split select/option #1508

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions .changeset/orange-clocks-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@alfalab/core-components-select': minor
---

Добавлен сплит select/option
В select/shared добавлены OptionDesktop и OptionMobile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react';

import type { OptionProps } from '../../typings';

import { OptionDesktop } from './desktop/Component'
import { OptionMobile } from './mobile/Component'

export const OptionResponsive = ({mobile, ...props}: OptionProps) =>
mobile ? <OptionMobile {...props} /> : <OptionDesktop {...props} />
23 changes: 17 additions & 6 deletions packages/select/src/components/option/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ import React, { FC, isValidElement } from 'react';
import cn from 'classnames';

import { SIZE_TO_CLASSNAME_MAP } from '../../consts';
import { OptionProps } from '../../typings';
import { Checkmark as DefaultCheckMark } from '../checkmark';
import { Checkmark as DefaultMobileCheckmark } from '../checkmark-mobile';
import { OptionCommonProps } from '../../typings';

import styles from './index.module.css';
import type stylesDesktop from './desktop/index.module.css';
import type stylesMobile from './mobile/index.module.css';

export const Option: FC<OptionProps> = ({
type OptionPrivateProps = {
/**
* Мобильная версия option.
*/
mobile: boolean;
/**
* Стили
*/
styles: typeof stylesDesktop | typeof stylesMobile;
};

export const OptionBase: FC<OptionCommonProps & OptionPrivateProps> = ({
size = 48,
className,
option,
Expand All @@ -18,9 +28,10 @@ export const Option: FC<OptionProps> = ({
disabled,
multiple,
mobile,
Checkmark = mobile ? DefaultMobileCheckmark : DefaultCheckMark,
Checkmark,
innerProps,
dataTestId,
styles,
}) => {
const content = children || option.content || option.key;
const { showCheckMark = true } = option;
Expand Down
11 changes: 11 additions & 0 deletions packages/select/src/components/option/desktop/Component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

import type { OptionCommonProps } from '../../../typings';
import { Checkmark as DefaultCheckMark } from '../../checkmark';
import { OptionBase } from '../Component';

import styles from './index.module.css';

export const OptionDesktop = ({ Checkmark = DefaultCheckMark, ...props }: OptionCommonProps) => (
<OptionBase {...props} mobile={false} Checkmark={Checkmark} styles={styles} />
);
13 changes: 13 additions & 0 deletions packages/select/src/components/option/desktop/index.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@import '../../../../../vars/src/index.css';
@import '../../../vars.css';
@import '../index.module.css';

.highlighted {
background: var(--select-option-hover-background);
color: var(--select-option-hover-color);

&:before,
& + .option:before {
opacity: 0;
}
}
4 changes: 3 additions & 1 deletion packages/select/src/components/option/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './Component';
export * from './desktop/Component';
export * from './mobile/Component';
export { OptionResponsive as Option } from './Component.responsive';
11 changes: 11 additions & 0 deletions packages/select/src/components/option/mobile/Component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

import type { OptionCommonProps } from '../../../typings';
import { Checkmark as DefaultCheckMark } from '../../checkmark-mobile';
import { OptionBase } from '../Component';

import styles from './index.module.css';

export const OptionMobile = ({ Checkmark = DefaultCheckMark, ...props }: OptionCommonProps) => (
<OptionBase {...props} mobile={true} Checkmark={Checkmark} styles={styles} />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@import '../../../../../vars/src/index.css';
@import '../../../vars.css';
@import '../index.module.css';
6 changes: 4 additions & 2 deletions packages/select/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ export type OptgroupProps = {
multiple?: boolean;
};

export type OptionProps = {
export type OptionCommonProps = {
/**
* Дополнительный класс
*/
Expand Down Expand Up @@ -795,9 +795,11 @@ export type OptionProps = {
* Выравнивание чекбокса или иконки "галочки"
*/
align?: 'start' | 'center';
};

export type OptionProps = OptionCommonProps & {
/**
* Мобильная верcия option.
* Мобильная версия option.
*/
mobile?: boolean;
};
Expand Down
Loading