Web: Components: Adapt Text component to RTL interface
This commit is contained in:
parent
98e31c2d7a
commit
d384e2fc9d
@ -1,8 +1,10 @@
|
||||
import { css } from "styled-components";
|
||||
import getTextAlign from "./utils/getTextAlign";
|
||||
|
||||
const commonTextStyles = css`
|
||||
font-family: ${(props) => props.theme.fontFamily};
|
||||
text-align: ${(props) => props.textAlign};
|
||||
text-align: ${(props) =>
|
||||
getTextAlign(props.textAlign, props.theme.interfaceDirection)};
|
||||
color: ${(props) =>
|
||||
props.colorProp ? props.colorProp : props.theme.text.color};
|
||||
${(props) =>
|
||||
|
@ -45,6 +45,6 @@ const StyledText = styled.p`
|
||||
${(props) => props.noSelect && NoUserSelect}
|
||||
`;
|
||||
|
||||
StyledText.defaultProps = { theme: Base };
|
||||
StyledText.defaultProps = { theme: { ...Base, interfaceDirection: "ltr" } };
|
||||
|
||||
export default StyledText;
|
||||
|
17
packages/components/text/utils/getTextAlign.js
Normal file
17
packages/components/text/utils/getTextAlign.js
Normal file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Returns correct text-align value depending on interface direction (ltr/rtl)
|
||||
*/
|
||||
const getTextAlign = (currentTextAlign, interfaceDirection) => {
|
||||
if (interfaceDirection === "ltr") return currentTextAlign;
|
||||
|
||||
switch (currentTextAlign) {
|
||||
case "left":
|
||||
return "right";
|
||||
case "right":
|
||||
return "left";
|
||||
default:
|
||||
return currentTextAlign;
|
||||
}
|
||||
};
|
||||
|
||||
export default getTextAlign;
|
Loading…
Reference in New Issue
Block a user