Skip to content

Commit

Permalink
feat(Settings): added onlyChild option to the Settings.Section (#298)
Browse files Browse the repository at this point in the history
Co-authored-by: Angelina Gadzhieva <[email protected]>
  • Loading branch information
melikhov-dev and Lunory authored Aug 22, 2024
1 parent 8aeb001 commit 7fe46f5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/components/Settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The components provides layouting functionality of settings panel with the follo
| header | ReactNode | | | Header of section |
| withBadge | boolean | | | Show badge on a section and menu |
| showTitle | boolean | | | Show section title. Prop is needed to hide title in simple settings on Mobile |
| onlyChild | boolean | | | Hide title if only one Settings.Section exists on page. |

#### Settings.Item

Expand Down
8 changes: 8 additions & 0 deletions src/components/Settings/Settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ $block: '.#{variables.$ns}settings';
& + & {
margin-top: 32px;
}

&_only-child:only-child &-item:first-of-type {
margin-top: 0px;
}

&_only-child:only-child &-heading {
display: none;
}
}

&__item {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface SettingsSectionProps {
children: React.ReactNode;
withBadge?: boolean;
showTitle?: boolean;
onlyChild?: boolean;
}

export interface SettingsItemProps {
Expand Down Expand Up @@ -232,7 +233,7 @@ function SettingsContent({
return (
<div
key={section.title}
className={b('section', {selected: isSelected})}
className={b('section', {selected: isSelected, 'only-child': section.onlyChild})}
ref={isSelected ? selected.selectedRef : undefined}
>
{section.showTitle && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Settings/__stories__/SettingsDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ function renderGeneralSettings(
return (
<Settings.Group id="general" groupTitle="General">
<Settings.Page id="appearance" title="Appearance" icon={{data: featureIcon}}>
<Settings.Section title="Appearance">
<Settings.Section title="Appearance" onlyChild={true}>
<Settings.Item title="Interface language">
<RadioButton
value={settings.lang ?? 'ru'}
Expand Down
1 change: 1 addition & 0 deletions src/components/Settings/collect-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface SettingsPageSection {
hidden?: boolean;
withBadge?: boolean;
showTitle?: boolean;
onlyChild?: boolean;
}

export interface SettingsItem {
Expand Down

0 comments on commit 7fe46f5

Please sign in to comment.