Skip to content

Commit

Permalink
feat: Add search for mobile view
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Oct 3, 2024
1 parent bd89846 commit d9ce237
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 8 deletions.
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@diplodoc/latex-extension": "^1.0.2",
"@diplodoc/mermaid-extension": "^1.2.1",
"@diplodoc/transform": "^4.31.3",
"@gravity-ui/icons": "^2.11.0",
"url": "^0.11.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/components/ConstructorPage/useNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const useNavigation = (
withBorder: true,
leftItems: leftItems,
rightItems: rightItems,
customMobileHeaderItems: [{type: 'search'} as unknown as NavigationItemModel],
}),
[leftItems, rightItems],
);
Expand Down
56 changes: 55 additions & 1 deletion src/components/Search/Suggest.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,66 @@
.Suggest {
display: flex;
justify-content: flex-end;
align-items: center;
float: right;

margin-right: 20px;
min-width: 200px;
transition: min-width 0.3s;
transition:
min-width 0.3s,
max-width 0.3s;

.dc-root_focused-search & {
min-width: 500px;
}

.mobile & {
margin-right: 0;
min-width: 36px;
max-width: 36px;
}

.mobile.dc-root_focused-search & {
min-width: 100%;
max-width: 100%;
}

&__close {
display: none;
flex: none;
margin-left: 16px;

.mobile.dc-root_focused-search & {
display: block;
}
}

&__end {
display: none;

.mobile & {
display: block;
}
}

&__input {
& input::placeholder {
transition: color 0.1s;
}

.mobile:not(.dc-root_focused-search) & {
--g-text-input-placeholder-color: rgba(0, 0, 0, 0);

& input {
padding: 0;
}

& > * {
border-color: rgba(0, 0, 0, 0);
}
}
}

&__Item {
&__Marker {
background: var(--g-color-base-neutral-medium);
Expand Down
14 changes: 13 additions & 1 deletion src/components/Search/Suggest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ import type {ISearchProvider, SearchSuggestApi} from '@diplodoc/components';

import React, {useCallback, useRef} from 'react';
import {SearchSuggest} from '@diplodoc/components';
import {Icon} from '@gravity-ui/uikit';
import {Magnifier} from '@gravity-ui/icons';
import block from 'bem-cn-lite';

import {updateRootClassName} from '../../utils';

import {useProvider} from './useProvider';
import './Suggest.scss';

const b = block('Suggest');

function SearchButton() {
return <Icon data={Magnifier} className={b('end')} size={24} />;
}

export function Suggest() {
const provider: ISearchProvider | null = useProvider();
const suggest = useRef<SearchSuggestApi>(null);
Expand Down Expand Up @@ -35,7 +44,10 @@ export function Suggest() {
provider={provider}
onFocus={onFocus}
onBlur={onBlur}
classNameContainer={'Suggest'}
endContent={<SearchButton />}
className={b('input')}
classNameContainer={b()}
closeButton={true}
/>
);
}
47 changes: 43 additions & 4 deletions src/styles/overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@
z-index: 120;

& > .container-fluid {
.desktop & {
padding-right: $desktopHPadding;
padding-left: $desktopHPadding;
}
padding-right: $desktopHPadding;
padding-left: $desktopHPadding;

.mobile & {
padding-right: $mobileRPadding;
Expand Down Expand Up @@ -157,3 +155,44 @@
}
}
}

.mobile {
.pc-navigation {
.pc-overflow-scroller {
justify-content: flex-end;
overflow: visible;
}
}
}

.mobile.dc-root_focused-search {
.pc-navigation {
.pc-desktop-navigation {
&__left,
&__navigation-container {
display: none;
}

&__right {
flex: 1 1 100%;
max-width: 100%;
}

&__mobile-navigation-container {
padding-right: 0;
}
}

.pc-overflow-scroller__wrapper {
width: 100%;
}

.pc-navigation-item:has(> .Suggest) {
width: 100%;
}

.pc-mobile-menu-button {
display: none;
}
}
}

0 comments on commit d9ce237

Please sign in to comment.