Skip to content

Commit

Permalink
feat(SubnavigationButton): add appearance (#5527)
Browse files Browse the repository at this point in the history
* feat(SubnavigationButton): add appearance
- closed #5525

* feat: update counter color

* chore: styles object
  • Loading branch information
SevereCloud authored Jul 28, 2023
1 parent a599170 commit 1091c34
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 35 deletions.
14 changes: 13 additions & 1 deletion packages/vkui/src/components/SubnavigationButton/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

```jsx { "props": { "layout": false, "iframe": false } }
const SubnavigationButtonExample = () => {
const [appearance, setAppearance] = useState('accent');
const [textLevel, setTextLevel] = useState('2');
const [sizeY, setSizeY] = useState('compact');
const [size, setSize] = useState('m');
Expand All @@ -29,11 +30,12 @@ const SubnavigationButtonExample = () => {
width: '100%',
}}
>
{['primary', 'tertiary', 'outline'].map((mode) => (
{['primary', 'outline', 'tertiary'].map((mode) => (
<Div key={mode}>
<SubnavigationButton
textLevel={textLevel}
mode={mode}
appearance={appearance}
size={size}
before={buttonBefore}
after={buttonAfter}
Expand All @@ -47,6 +49,16 @@ const SubnavigationButtonExample = () => {
</div>
</AdaptivityProvider>
<div style={{ minWidth: 200 }}>
<FormItem top="appearance">
<Select
value={appearance}
onChange={(e) => setAppearance(e.target.value)}
options={[
{ label: 'accent', value: 'accent' },
{ label: 'neutral', value: 'neutral' },
]}
/>
</FormItem>
<FormItem top="text level">
<Select
value={textLevel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const SubnavigationButtonPlayground = (props: ComponentPlaygroundProps) =
selected: [undefined, true],
before: [<Icon24Filter key="icon" />],
mode: ['primary', 'outline', 'tertiary'],
appearance: ['accent', 'neutral'],
after: [
<Counter key="counter" size="s">
3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@
box-shadow: inset 0 0 0 var(--vkui_internal--thin_border) var(--vkui--color_field_border_alpha);
}

/**
* appearance
*/

.SubnavigationButton--appearance-neutral .SubnavigationButton__expandableIcon,
.SubnavigationButton--appearance-neutral .SubnavigationButton__before {
color: var(--vkui--color_icon_primary);
}

/**
* selected
*/
Expand All @@ -120,14 +129,19 @@
border: 0;
}

.SubnavigationButton--selected.SubnavigationButton--mode-tertiary {
.SubnavigationButton--selected.SubnavigationButton--mode-tertiary,
.SubnavigationButton--selected.SubnavigationButton--appearance-neutral {
background-color: var(--vkui--color_transparent--active);
color: var(--vkui--color_text_primary);
}

.SubnavigationButton--selected:not(.SubnavigationButton--mode-tertiary)
.SubnavigationButton--selected.SubnavigationButton--appearance-accent:not(
.SubnavigationButton--mode-tertiary
)
.SubnavigationButton__before,
.SubnavigationButton--selected:not(.SubnavigationButton--mode-tertiary)
.SubnavigationButton--selected.SubnavigationButton--appearance-accent:not(
.SubnavigationButton--mode-tertiary
)
.SubnavigationButton__expandableIcon {
color: var(--vkui--color_icon_contrast_themed);
}
Expand All @@ -142,11 +156,18 @@
--vkui_internal--counter_inherit_color: var(--vkui--color_text_contrast_themed);
}

.SubnavigationButton--selected:not(.SubnavigationButton--mode-tertiary) {
.SubnavigationButton--selected.SubnavigationButton--appearance-accent:not(
.SubnavigationButton--mode-tertiary
) {
--vkui_internal--counter_inherit_background: var(--vkui--color_background_content);
--vkui_internal--counter_inherit_color: var(--vkui--color_text_accent_themed);
}

.SubnavigationButton--selected.SubnavigationButton--appearance-neutral {
--vkui_internal--counter_inherit_background: var(--vkui--color_background_content);
--vkui_internal--counter_inherit_color: var(--vkui--color_text_primary);
}

:global(.vkuiInternalSubnavigationBar--mode-fixed) .SubnavigationButton {
flex: 1;
min-width: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,31 @@ import { Caption } from '../Typography/Caption/Caption';
import { Subhead } from '../Typography/Subhead/Subhead';
import styles from './SubnavigationButton.module.css';

const appearanceStyles = {
accent: styles['SubnavigationButton--appearance-accent'],
neutral: styles['SubnavigationButton--appearance-neutral'],
};

const modeStyles = {
primary: styles['SubnavigationButton--mode-primary'],
outline: styles['SubnavigationButton--mode-outline'],
tertiary: styles['SubnavigationButton--mode-tertiary'],
};

const sizeStyles = {
s: styles['SubnavigationButton--size-s'],
m: styles['SubnavigationButton--size-m'],
l: styles['SubnavigationButton--size-l'],
};

const sizeYClassNames = {
none: styles['SubnavigationButton--sizeY-none'],
[SizeType.COMPACT]: styles['SubnavigationButton--sizeY-compact'],
};

export interface SubnavigationButtonProps extends Omit<TappableProps, 'size'> {
mode?: 'primary' | 'outline' | 'tertiary';
appearance?: 'accent' | 'neutral';
size?: 's' | 'm' | 'l';
selected?: boolean;
/**
Expand Down Expand Up @@ -56,6 +74,7 @@ const SubnavigationButtonTypography = ({
*/
export const SubnavigationButton = ({
mode = 'primary',
appearance = 'accent',
size = 'm',
selected,
textLevel = '1',
Expand All @@ -75,16 +94,9 @@ export const SubnavigationButton = ({
focusVisibleMode="outside"
className={classNames(
styles['SubnavigationButton'],
{
s: styles['SubnavigationButton--size-s'],
m: styles['SubnavigationButton--size-m'],
l: styles['SubnavigationButton--size-l'],
}[size],
{
primary: styles['SubnavigationButton--mode-primary'],
outline: styles['SubnavigationButton--mode-outline'],
tertiary: styles['SubnavigationButton--mode-tertiary'],
}[mode],
sizeStyles[size],
modeStyles[mode],
appearanceStyles[appearance],
selected && styles['SubnavigationButton--selected'],
sizeY !== SizeType.REGULAR && sizeYClassNames[sizeY],
className,
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 1091c34

Please sign in to comment.