Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(!): uikit update #207

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions demo/.storybook/decorators/withTheme.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import type {Decorator} from '@storybook/react';
import {ThemeProvider} from '@gravity-ui/uikit';

export const WithTheme: Decorator = (Story, context) => {
return (
<ThemeProvider theme={context.globals.theme}>
<Story />
</ThemeProvider>
);
};
5 changes: 4 additions & 1 deletion demo/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/** @type { import('@storybook/react').Preview } */
import { Preview } from '@storybook/react';
import type {Preview} from '@storybook/react';

import {WithTheme} from './decorators/withTheme';

import './global.css';

const preview: Preview = {
decorators: [WithTheme],
parameters: {
actions: {argTypesRegex: '^on[A-Z].*'},
controls: {
Expand Down
8,540 changes: 4,860 additions & 3,680 deletions demo/package-lock.json

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@
"@babel/preset-env": "^7.22.14",
"@babel/preset-react": "^7.22.5",
"@babel/preset-typescript": "^7.22.11",
"@storybook/addon-essentials": "^7.4.0",
"@storybook/addon-interactions": "^7.4.0",
"@storybook/addon-essentials": "^7.6.17",
"@storybook/addon-interactions": "^7.6.17",
"@storybook/addon-knobs": "^7.0.2",
"@storybook/addon-links": "^7.4.0",
"@storybook/addon-links": "^7.6.17",
"@storybook/addon-onboarding": "^1.0.8",
"@storybook/addon-styling": "^1.3.7",
"@storybook/blocks": "^7.4.0",
"@storybook/react": "^7.4.0",
"@storybook/react-webpack5": "^7.4.0",
"@storybook/blocks": "^7.6.17",
"@storybook/react": "^7.6.17",
"@storybook/react-webpack5": "^7.6.17",
"@storybook/testing-library": "^0.2.0",
"@svgr/webpack": "^8.1.0",
"sass": "^1.66.1",
"storybook": "^7.4.0"
"storybook": "^7.6.17"
},
"dependencies": {
"@diplodoc/components": "^3.0.0-alpha-7",
"@diplodoc/components": "^3.10.0-beta.0",
"@doc-tools/transform": "^3.10.3",
"@gravity-ui/uikit": "^6.0.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
8 changes: 5 additions & 3 deletions src/components/Control/Control.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, {forwardRef, useCallback, useImperativeHandle, useRef} from 'react';

import {Button, ButtonProps, Popup} from '@gravity-ui/uikit';
import {Button, ButtonProps, Popup, useDirection} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';

import {PopperPosition, usePopupState} from '../../hooks';
import {ControlSizes} from '../../models';
import {getPopupPosition} from '../../utils';

import './Control.scss';

Expand Down Expand Up @@ -57,14 +58,15 @@ const Control = forwardRef((props: ControlProps, ref) => {
const controlRef = useRef<HTMLButtonElement | null>(null);

const popupState = usePopupState({autoclose: 3000});
const direction = useDirection();

const getTooltipAlign = useCallback(() => {
if (popupPosition) {
return popupPosition;
}

return isVerticalView ? PopperPosition.LEFT_START : PopperPosition.BOTTOM_END;
}, [isVerticalView, popupPosition]);
return getPopupPosition(isVerticalView, direction);
}, [isVerticalView, popupPosition, direction]);

useImperativeHandle(ref, () => controlRef.current, [controlRef]);

Expand Down
3 changes: 0 additions & 3 deletions src/components/Controls/Controls.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@

@include focusable(-2px);

[dir='rtl'] & {
flex-direction: row-reverse;
}
}

&__icon-rotated {
Expand Down
3 changes: 1 addition & 2 deletions src/components/Controls/single-controls/LangControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import allLangs from 'langs';

import {usePopupState, useTranslation} from '../../../hooks';
import {Lang} from '../../../models';
import {getPopupPosition} from '../../../utils';
import {Control} from '../../Control';
import {ControlsLayoutContext} from '../ControlsLayout';

import {getPopupPosition} from './utils';

import '../Controls.scss';

const ICONS: Record<string, string> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
display: flex;
align-items: center;

[dir='rtl'] & {
flex-direction: row-reverse;
}
}

&__text-size-button {
Expand Down Expand Up @@ -55,9 +52,6 @@
padding: 12px;
width: 100%;

[dir='rtl'] & {
flex-direction: row-reverse;
}
}

&__list-item-description {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, {ReactElement, useCallback, useContext, useRef, useState} from 'react';

import {Gear} from '@gravity-ui/icons';
import {Button, List, Popover, Switch} from '@gravity-ui/uikit';
import {Button, List, Popover, Switch, useDirection} from '@gravity-ui/uikit';
import cn from 'bem-cn-lite';

import {useTranslation} from '../../../../hooks';
import {TextSizes, Theme} from '../../../../models';
import {getPopupPosition} from '../../../../utils';
import {Control} from '../../../Control';
import {ControlsLayoutContext} from '../../ControlsLayout';
import {getPopupPosition} from '../utils';

import './SettingsControl.scss';

Expand Down Expand Up @@ -52,6 +52,8 @@ const SettingsControl = (props: ControlProps) => {
} = props;

const controlRef = useRef<HTMLButtonElement | null>(null);
const direction = useDirection();

const [isVisiblePopup, setIsVisiblePopup] = useState(false);
const showPopup = () => setIsVisiblePopup(true);
const hidePopup = () => setIsVisiblePopup(false);
Expand Down Expand Up @@ -175,7 +177,7 @@ const SettingsControl = (props: ControlProps) => {
restoreFocusRef={controlRef}
onCloseClick={hidePopup}
onOpenChange={setIsVisiblePopup}
placement={getPopupPosition(isVerticalView)}
placement={getPopupPosition(isVerticalView, direction)}
className={controlClassName}
contentClassName={b('popup')}
tooltipClassName={b('popup-tooltip')}
Expand Down
5 changes: 0 additions & 5 deletions src/components/Controls/single-controls/utils.ts

This file was deleted.

92 changes: 44 additions & 48 deletions src/components/DocPage/DocPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, {ReactPortal} from 'react';

import {Link} from '@gravity-ui/icons';
import {ThemeProvider} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import {createPortal} from 'react-dom';

Expand Down Expand Up @@ -134,7 +133,6 @@ class DocPage extends React.Component<DocPageInnerProps, DocPageState> {
footer,
onChangeSinglePage,
pdfLink,
theme,
} = this.props;

const hideMiniToc = !this.showMiniToc;
Expand All @@ -146,52 +144,50 @@ class DocPage extends React.Component<DocPageInnerProps, DocPageState> {
};

return (
<ThemeProvider theme={theme}>
<DocLayout
toc={toc}
router={router}
headerHeight={headerHeight}
className={b(modes)}
fullScreen={fullScreen}
hideRight={hideMiniToc}
tocTitleIcon={tocTitleIcon}
wideFormat={wideFormat}
hideTocHeader={hideTocHeader}
hideToc={hideToc}
loading={this.state.loading}
footer={footer}
singlePage={singlePage}
onChangeSinglePage={onChangeSinglePage}
pdfLink={pdfLink}
>
<DocLayout.Center>
{this.renderSearchBar()}
{this.renderBreadcrumbs()}
{this.renderControls()}
<div className={b('main')}>
<main className={b('content')}>
{this.renderTitle()}
{this.renderPageContributors()}
{hideMiniToc ? null : this.renderContentMiniToc()}
{this.renderBody()}
{this.renderFeedback()}
</main>
{this.renderTocNavPanel()}
</div>
{this.renderLoader()}
{this.renderSinglePageControls()}
</DocLayout.Center>
<DocLayout.Right>
{/* This key allows recalculating the offset for the mini-toc for Safari */}
<div
className={b('aside')}
key={getStateKey(this.showMiniToc, wideFormat, singlePage)}
>
{hideMiniToc ? null : this.renderAsideMiniToc()}
</div>
</DocLayout.Right>
</DocLayout>
</ThemeProvider>
<DocLayout
toc={toc}
router={router}
headerHeight={headerHeight}
className={b(modes)}
fullScreen={fullScreen}
hideRight={hideMiniToc}
tocTitleIcon={tocTitleIcon}
wideFormat={wideFormat}
hideTocHeader={hideTocHeader}
hideToc={hideToc}
loading={this.state.loading}
footer={footer}
singlePage={singlePage}
onChangeSinglePage={onChangeSinglePage}
pdfLink={pdfLink}
>
<DocLayout.Center>
{this.renderSearchBar()}
{this.renderBreadcrumbs()}
{this.renderControls()}
<div className={b('main')}>
<main className={b('content')}>
{this.renderTitle()}
{this.renderPageContributors()}
{hideMiniToc ? null : this.renderContentMiniToc()}
{this.renderBody()}
{this.renderFeedback()}
</main>
{this.renderTocNavPanel()}
</div>
{this.renderLoader()}
{this.renderSinglePageControls()}
</DocLayout.Center>
<DocLayout.Right>
{/* This key allows recalculating the offset for the mini-toc for Safari */}
<div
className={b('aside')}
key={getStateKey(this.showMiniToc, wideFormat, singlePage)}
>
{hideMiniToc ? null : this.renderAsideMiniToc()}
</div>
</DocLayout.Right>
</DocLayout>
);
}

Expand Down
9 changes: 6 additions & 3 deletions src/components/Feedback/controls/DislikeVariantsPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import React, {
useState,
} from 'react';

import {Button, Checkbox, Popup, TextArea} from '@gravity-ui/uikit';
import {Button, Checkbox, Popup, TextArea, useDirection} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';

import {PopperPosition, useTranslation} from '../../../hooks';
import {getPopupPosition} from '../../../utils';
import {ControlsLayoutContext} from '../../Controls/ControlsLayout';
import {FeedbackView} from '../Feedback';

Expand Down Expand Up @@ -131,13 +132,15 @@ const DislikeVariantsPopup: React.FC<DislikeVariantsPopupProps> = memo(
({anchor, visible, view, onOutsideClick, onSubmit}) => {
const {t} = useTranslation('feedback');
const {isVerticalView} = useContext(ControlsLayoutContext);
const direction = useDirection();

const position = useMemo(() => {
if (!view || view === FeedbackView.Regular) {
return isVerticalView ? PopperPosition.LEFT_START : PopperPosition.BOTTOM_END;
return getPopupPosition(isVerticalView, direction);
}

return PopperPosition.RIGHT;
}, [isVerticalView, view]);
}, [isVerticalView, view, direction]);

const feedbackComment = useRef<FormPart<string> | null>(null);
const feedbackCheckboxes = useRef<FormPart<string[]> | null>(null);
Expand Down
9 changes: 6 additions & 3 deletions src/components/Feedback/controls/SuccessPopup.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, {RefObject, memo, useContext, useMemo} from 'react';

import {Popup} from '@gravity-ui/uikit';
import {Popup, useDirection} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';

import {PopperPosition, useTranslation} from '../../../hooks';
import {getPopupPosition} from '../../../utils';
import {ControlsLayoutContext} from '../../Controls/ControlsLayout';
import {FeedbackView} from '../Feedback';

Expand All @@ -19,13 +20,15 @@ const b = block('dc-feedback');
const SuccessPopup = memo<SuccessPopupProps>(({visible, anchor, onOutsideClick, view}) => {
const {t} = useTranslation('feedback');
const {isVerticalView} = useContext(ControlsLayoutContext);
const direction = useDirection();

const position = useMemo(() => {
if (!view || view === FeedbackView.Regular) {
return isVerticalView ? PopperPosition.LEFT_START : PopperPosition.BOTTOM_END;
return getPopupPosition(isVerticalView, direction);
}

return PopperPosition.RIGHT;
}, [isVerticalView, view]);
}, [isVerticalView, view, direction]);

return (
<Popup
Expand Down
16 changes: 10 additions & 6 deletions src/components/Paginator/Paginator.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
display: flex;
align-items: center;

[dir='rtl'] & {
flex-direction: row-reverse;
justify-content: flex-end;
}

&__item {
$item: &;
Expand All @@ -30,7 +26,11 @@

&_type {
&_prev {
margin-left: -6px;
margin: 4px 6px 4px 0;

[dir='rtl'] & {
transform: rotate(180deg);
}
}

&_dots {
Expand All @@ -54,7 +54,11 @@
}

&_next {
margin-right: -6px;
margin: 4px 0 4px 6px;

[dir='rtl'] & {
transform: rotate(180deg);
}
}
}
}
Expand Down
Loading
Loading