Skip to content

Commit

Permalink
feat(select): add option split;
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis 🎃 Khripkov committed Dec 18, 2024
1 parent bd71aed commit 983edf5
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 9 deletions.
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} />
);
3 changes: 3 additions & 0 deletions packages/select/src/components/option/mobile/index.module.css
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

0 comments on commit 983edf5

Please sign in to comment.