Skip to content

Commit

Permalink
feat(SegmentedControl): add before (#5959)
Browse files Browse the repository at this point in the history
  • Loading branch information
SevereCloud authored Oct 12, 2023
1 parent cde31aa commit 17ff58b
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ export const SegmentedControlPlayground = (props: ComponentPlaygroundProps) => {
size: ['m', 'l'],
$adaptivity: 'y',
},
{
options: [
[
{ label: 'vk', before: <Icon24LogoVk />, value: 'vk' },
{ label: 'fb', before: <Icon24LogoFacebook />, value: 'fb' },
{ label: 'google', before: <Icon24LogoGoogle />, value: 'google' },
],
],
},
]}
>
{(props: SegmentedControlProps) => <SegmentedControl {...props} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@
0 3px 1px rgba(0, 0, 0, 0.04);
}

.SegmentedControl__option {
position: relative;
flex: 1;
display: block;
margin: 0;
padding: 0;
}

/**
* sizeY REGULAR
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export type SegmentedControlValue = string | number | undefined;

export interface SegmentedControlOptionInterface
extends Omit<React.HTMLAttributes<HTMLElement>, 'label'> {
/**
* Вставляет элемент перед основным контентом.
* Рекомендуется использовать только иконки с размером 20
*/
before?: React.ReactNode;
label: React.ReactChild;
value: SegmentedControlValue;
}
Expand Down Expand Up @@ -90,11 +95,10 @@ export const SegmentedControl = ({
}}
/>
)}
{options.map(({ label, className: optionClassName, ...optionProps }) => (
{options.map(({ label, ...optionProps }) => (
<SegmentedControlOption
key={`${optionProps.value}`}
{...optionProps}
className={classNames(styles['SegmentedControl__option'], optionClassName)}
name={name ?? id}
checked={value === optionProps.value}
onChange={() => onChange(optionProps.value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@
box-sizing: border-box;
cursor: pointer;
appearance: none;
}

.SegmentedControlOption :global(.vkuiIcon) {
color: var(--vkui--color_icon_primary);
display: flex;
position: relative;
justify-content: center;
align-items: center;
flex: 1;
}

.SegmentedControlOption:not(.SegmentedControlOption--checked):hover {
opacity: 0.5;
}

.SegmentedControlOption__content {
display: flex;
align-content: center;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
border-radius: inherit;
.SegmentedControlOption__before {
margin-right: 6px;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { classNames } from '@vkontakte/vkjs';
import { classNames, hasReactNode } from '@vkontakte/vkjs';
import { useFocusVisible } from '../../../hooks/useFocusVisible';
import { callMultiple } from '../../../lib/callMultiple';
import { HasRef, HasRootRef } from '../../../types';
Expand All @@ -11,7 +11,9 @@ import styles from './SegmentedControlOption.module.css';
export interface SegmentedControlOptionProps
extends React.InputHTMLAttributes<HTMLInputElement>,
HasRootRef<HTMLLabelElement>,
HasRef<HTMLInputElement> {}
HasRef<HTMLInputElement> {
before?: React.ReactNode;
}

/**
* @see https://vkcom.github.io/VKUI/#/SegmentedControl
Expand All @@ -22,6 +24,7 @@ export const SegmentedControlOption = ({
style,
children,
getRootRef,
before,
...restProps
}: SegmentedControlOptionProps) => {
const { focusVisible, onBlur, onFocus } = useFocusVisible();
Expand All @@ -44,7 +47,10 @@ export const SegmentedControlOption = ({
onBlur={callMultiple(onBlur, restProps.onBlur)}
onFocus={callMultiple(onFocus, restProps.onFocus)}
/>
<Headline className={styles['SegmentedControlOption__content']} level="2" weight="2">
{hasReactNode(before) && (
<div className={styles['SegmentedControlOption__before']}>{before}</div>
)}
<Headline level="2" weight="2">
{children}
</Headline>
<FocusVisible visible={focusVisible} mode="inside" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 17ff58b

Please sign in to comment.