Skip to content

Commit

Permalink
docs: add dir and writing mode (#6703)
Browse files Browse the repository at this point in the history
Добавляем для сторибука возможность переключать направление текста
  • Loading branch information
SevereCloud authored and actions-user committed Mar 18, 2024
1 parent 3370c72 commit 591794f
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
21 changes: 21 additions & 0 deletions packages/vkui/.storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ const preview: Preview = {
description: 'Hide "after" prop of PanelHeader for custom floating "after" element',
defaultValue: false,
},
direction: {
name: 'Direction',
description: "Attribute indicating the directionality of the element's text",
defaultValue: 'ltr',
toolbar: {
items: [
{ value: 'ltr', icon: 'menu', title: 'ltr' },
{ value: 'rtl', icon: 'menualt', title: 'rtl' },
],
},
},
writingMode: {
name: 'Writing mode',
description:
'Sets whether lines of text are laid out horizontally or vertically, as well as the direction in which blocks progress',
defaultValue: 'horizontal-tb',
toolbar: {
icon: 'redirect',
items: ['horizontal-tb', 'vertical-rl', 'vertical-lr'],
},
},
},
argTypes: {
getRef: { control: false },
Expand Down
3 changes: 2 additions & 1 deletion packages/vkui/scripts/postcss.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function makePostcssPlugins({
isProduction = process.env.NODE_ENV === 'production',
isCssModulesFile = false,
isESNext = false,
isStorybook = process.env.SANDBOX === '.storybook',
} = {}) {
const plugins = [
// Обработка css импортов
Expand Down Expand Up @@ -55,7 +56,7 @@ function makePostcssPlugins({
// Обработка CSS Logical
//
// https://caniuse.com/css-logical-props
if (!isESNext) {
if (!isESNext && !isStorybook) {
plugins.push(postcssLogical());
}

Expand Down
1 change: 1 addition & 0 deletions packages/vkui/src/components/AppRoot/AppRoot.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.AppRoot {
block-size: 100%;
inline-size: 100%;
}

.AppRoot--pointer-has-not {
Expand Down
16 changes: 14 additions & 2 deletions packages/vkui/src/storybook/VKUIDecorators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ const CenteredStyle: React.CSSProperties = {
const channel = addons.getChannel();

export const withVKUIWrapper: Decorator = (Component, context) => {
const { platform, appearance, hasPointer = false, hasCustomPanelHeaderAfter } = context.globals;
const {
platform,
appearance,
hasPointer = false,
hasCustomPanelHeaderAfter,
direction,
writingMode,
} = context.globals;

// eslint-disable-next-line no-restricted-properties, react-hooks/rules-of-hooks
React.useLayoutEffect(() => {
Expand All @@ -38,14 +45,19 @@ export const withVKUIWrapper: Decorator = (Component, context) => {

const { centered } = context.parameters;

const style: React.CSSProperties = {
writingMode,
...(centered ? CenteredStyle : {}),
};

return (
<ConfigProvider
platform={platform}
appearance={appearance}
hasCustomPanelHeaderAfter={hasCustomPanelHeaderAfter}
>
<AdaptivityProvider hasPointer={hasPointer}>
<AppRoot style={centered ? CenteredStyle : undefined}>
<AppRoot style={style} dir={direction}>
<Component />
</AppRoot>
</AdaptivityProvider>
Expand Down

0 comments on commit 591794f

Please sign in to comment.