-
Notifications
You must be signed in to change notification settings - Fork 185
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(DirectionProvider): add direction to ConfigProvider #8236
base: master
Are you sure you want to change the base?
Conversation
# Conflicts: # packages/vkui/src/testing/e2e/ComponentPlayground.tsx
size-limit report 📦
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
e2e tests
|
👀 Docs deployed
Commit 610cc81 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #8236 +/- ##
==========================================
- Coverage 95.54% 95.43% -0.12%
==========================================
Files 404 406 +2
Lines 11605 11610 +5
Branches 3853 3845 -8
==========================================
- Hits 11088 11080 -8
- Misses 517 530 +13
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
# Conflicts: # packages/vkui/src/components/Pagination/Pagination.tsx # packages/vkui/src/testing/e2e/ComponentPlayground.tsx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Отличная работа 🎉
packages/vkui/src/components/ConfigProvider/ConfigProviderContext.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
if (!window || !document) { | ||
return; | ||
} | ||
const styleDeclaration = window.getComputedStyle(document.body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dir
зачастую определяют на <html>
, тут либо нужно возможность завязаться на html
или body
, либо проверять всё же <html>
и в доке об этом говорить
https://www.w3.org/International/questions/qa-html-dir#rtlsetup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
если даже dir будет установлен на html, то у body будет то же значение, так что в целом не важно
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
раз у нас всё-равно есть ограничение, то что нам мешает значение для автодетекта брать до рендера? 🌚
const getGlobalDir = () => {
if (!document) {
return document.body.dir || document.documentElement.dir || 'ltr';
}
return 'ltr';
};
// ...
const direction = React.useMemo(getGlobalDir, []);
а для SSR в SSRWrapper
завести свойство
<SSRWrapper dir="ltr">
// ...
</SSRWrapper>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
раз у нас всё-равно есть ограничение, то что нам мешает значение для автодетекта брать до рендера?
Насчет этого согласен
а для SSR в
SSRWrapper
завести свойство
А вот насчет этого, не совсем понял зачем? Можешь объяснить?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а для SSR в
SSRWrapper
завести свойствоА вот насчет этого, не совсем понял зачем? Можешь объяснить?
в SSR нет доступа к DOM, поэтому нельзя узнать dir
, из-за чего в случае разметки:
<html>
<head></head>
<body dir="rtl">
</body>
</html>
на сервере у компонентов не будет CSS классов под RTL, а на клиенте будет – получим ошибку гидрации
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
понял, получается надо нам надо с помощью DirectionProvider переопределить dir в SSRWrapper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавил проп direction
Co-authored-by: Inomdzhon Mirdzhamolov <[email protected]>
…vider' into e.muhamethanov/rtl/direction-provider
Описание
Текущий подход использует хук
useDirection
, который определяетdirection
черезgetComputedStyle
при каждой первой отрисовке компонента. При большом количестве компонентов это влияет на производительность.Предлагаемое решение
Добавить direction как параметр в
ConfigProvider
, который можно:direction
уbody
Изменения
direction
вConfigProvider
DirectionProvider
для переопределения directionuseConfigDirection
ComponentPlayground
так чтобы поддерживался рендеринг компонентов вrtl
mockRtlDirection
Release notes
Новые компоненты
direction
Улучшения
direction
, который по умолчанию определяется исходя из атрибутаdir
вbody
страницы