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

add text alignment functionality to the TextAlignment component #561

Merged
merged 4 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const DEFAULT_TEXT_HEIGHT = 38;
const DEFAULT_FONT_VARIANT = 'normal';
const DEFAULT_FONT_STYLE = 'normal';
const DEFAULT_TEXT_DECORATION = 'none';
const DEFAULT_TEXT_ALIGNMENT = 'left';

export interface DefaultStyleShape {
DEFAULT_CORNER_RADIUS: number;
Expand All @@ -32,6 +33,7 @@ export interface DefaultStyleShape {
DEFAULT_FONT_VARIANT: string;
DEFAULT_FONT_STYLE: string;
DEFAULT_TEXT_DECORATION: string;
DEFAULT_TEXT_ALIGNMENT: 'left' | 'center' | 'right';
}

export const BASIC_SHAPE: DefaultStyleShape = {
Expand All @@ -50,6 +52,7 @@ export const BASIC_SHAPE: DefaultStyleShape = {
DEFAULT_FONT_VARIANT,
DEFAULT_FONT_STYLE,
DEFAULT_TEXT_DECORATION,
DEFAULT_TEXT_ALIGNMENT,
};

export const INPUT_SHAPE: DefaultStyleShape = {
Expand All @@ -68,6 +71,7 @@ export const INPUT_SHAPE: DefaultStyleShape = {
DEFAULT_FONT_VARIANT,
DEFAULT_FONT_STYLE,
DEFAULT_TEXT_DECORATION,
DEFAULT_TEXT_ALIGNMENT,
};

//! maybe a function to calc max height base on the text
Expand All @@ -87,6 +91,7 @@ export const POSTIT_SHAPE: DefaultStyleShape = {
DEFAULT_FONT_VARIANT,
DEFAULT_FONT_STYLE,
DEFAULT_TEXT_DECORATION,
DEFAULT_TEXT_ALIGNMENT,
};

interface FontValues {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ export const Heading1Shape = forwardRef<any, ShapeProps>((props, ref) => {
);
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;

const { textColor, textDecoration, fontStyle, fontVariant, fontSize } =
useShapeProps(otherProps, BASIC_SHAPE);
const {
textColor,
textDecoration,
fontStyle,
fontVariant,
fontSize,
textAlignment,
} = useShapeProps(otherProps, BASIC_SHAPE);

const commonGroupProps = useGroupShapeProps(
props,
Expand All @@ -61,7 +67,7 @@ export const Heading1Shape = forwardRef<any, ShapeProps>((props, ref) => {
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY}
fontSize={fontSize}
fill={textColor}
align="center"
align={textAlignment}
verticalAlign="middle"
ellipsis={true}
wrap="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ export const Heading2Shape = forwardRef<any, ShapeProps>((props, ref) => {
);
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;

const { textColor, fontVariant, fontStyle, textDecoration, fontSize } =
useShapeProps(otherProps, BASIC_SHAPE);
const {
textColor,
fontVariant,
fontStyle,
textDecoration,
fontSize,
textAlignment,
} = useShapeProps(otherProps, BASIC_SHAPE);

const commonGroupProps = useGroupShapeProps(
props,
Expand All @@ -61,7 +67,7 @@ export const Heading2Shape = forwardRef<any, ShapeProps>((props, ref) => {
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY}
fontSize={fontSize}
fill={textColor}
align="center"
align={textAlignment}
verticalAlign="middle"
ellipsis={true}
wrap="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ export const Heading3Shape = forwardRef<any, ShapeProps>((props, ref) => {

const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;

const { textColor, fontVariant, fontStyle, textDecoration, fontSize } =
useShapeProps(otherProps, BASIC_SHAPE);
const {
textColor,
fontVariant,
fontStyle,
textDecoration,
fontSize,
textAlignment,
} = useShapeProps(otherProps, BASIC_SHAPE);

const commonGroupProps = useGroupShapeProps(
props,
Expand All @@ -62,7 +68,7 @@ export const Heading3Shape = forwardRef<any, ShapeProps>((props, ref) => {
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY}
fontSize={fontSize}
fill={textColor}
align="center"
align={textAlignment}
verticalAlign="middle"
ellipsis={true}
wrap="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const LinkShape = forwardRef<any, ShapeProps>((props, ref) => {

const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;

const { textColor, textDecoration, fontSize } = useShapeProps(
const { textColor, textDecoration, fontSize, textAlignment } = useShapeProps(
otherProps,
BASIC_SHAPE
);
Expand All @@ -64,7 +64,7 @@ export const LinkShape = forwardRef<any, ShapeProps>((props, ref) => {
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY}
fontSize={fontSize}
fill={textColor}
align="center"
align={textAlignment}
verticalAlign="middle"
ellipsis={true}
wrap="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ export const NormaltextShape = forwardRef<any, ShapeProps>((props, ref) => {
);
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;

const { textColor, fontVariant, fontStyle, textDecoration, fontSize } =
useShapeProps(otherProps, BASIC_SHAPE);
const {
textColor,
fontVariant,
fontStyle,
textDecoration,
fontSize,
textAlignment,
} = useShapeProps(otherProps, BASIC_SHAPE);

const commonGroupProps = useGroupShapeProps(
props,
Expand All @@ -61,7 +67,7 @@ export const NormaltextShape = forwardRef<any, ShapeProps>((props, ref) => {
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY}
fontSize={fontSize}
fill={textColor}
align="center"
align={textAlignment}
verticalAlign="middle"
ellipsis={true}
wrap="none"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export const ParagraphShape = forwardRef<any, ShapeProps>((props, ref) => {
);
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;

const { textColor, fontSize } = useShapeProps(otherProps, BASIC_SHAPE);
const { textColor, fontSize, textAlignment } = useShapeProps(
otherProps,
BASIC_SHAPE
);

const commonGroupProps = useGroupShapeProps(
props,
Expand All @@ -60,7 +63,7 @@ export const ParagraphShape = forwardRef<any, ShapeProps>((props, ref) => {
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY}
fontSize={fontSize}
fill={textColor}
align="left"
align={textAlignment}
ellipsis={true}
/>
</Group>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ export const SmalltextShape = forwardRef<any, ShapeProps>((props, ref) => {
);
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;

const { textColor, fontVariant, fontStyle, textDecoration, fontSize } =
useShapeProps(otherProps, BASIC_SHAPE);
const {
textColor,
fontVariant,
fontStyle,
textDecoration,
fontSize,
textAlignment,
} = useShapeProps(otherProps, BASIC_SHAPE);

const commonGroupProps = useGroupShapeProps(
props,
Expand All @@ -61,7 +67,7 @@ export const SmalltextShape = forwardRef<any, ShapeProps>((props, ref) => {
fontFamily={BASIC_SHAPE.DEFAULT_FONT_FAMILY}
fontSize={fontSize}
fill={textColor}
align="center"
align={textAlignment}
verticalAlign="middle"
ellipsis={true}
wrap="none"
Expand Down
6 changes: 6 additions & 0 deletions src/common/components/shapes/use-shape-props.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export const useShapeProps = (
[otherProps?.textDecoration]
);

const textAlignment = useMemo(
() => otherProps?.textAlignment ?? defaultStyleShape.DEFAULT_TEXT_ALIGNMENT,
[otherProps?.textAlignment]
);

const strokeStyle = useMemo(
() => otherProps?.strokeStyle ?? [],
[otherProps?.strokeStyle]
Expand Down Expand Up @@ -81,5 +86,6 @@ export const useShapeProps = (
fontStyle,
fontSize,
textDecoration,
textAlignment,
};
};
7 changes: 7 additions & 0 deletions src/core/local-disk/shapes-to-document.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const mapTextElementFromV0_1ToV0_2 = (shape: ShapeModel): ShapeModel => {
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.HEADING1,
textAlignment: 'center',
},
};
case 'heading2':
Expand All @@ -38,6 +39,7 @@ const mapTextElementFromV0_1ToV0_2 = (shape: ShapeModel): ShapeModel => {
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.HEADING2,
textAlignment: 'center',
},
};
case 'heading3':
Expand All @@ -46,6 +48,7 @@ const mapTextElementFromV0_1ToV0_2 = (shape: ShapeModel): ShapeModel => {
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.HEADING3,
textAlignment: 'center',
},
};
case 'link':
Expand All @@ -54,6 +57,7 @@ const mapTextElementFromV0_1ToV0_2 = (shape: ShapeModel): ShapeModel => {
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.LINK,
textAlignment: 'center',
},
};
case 'normaltext':
Expand All @@ -62,6 +66,7 @@ const mapTextElementFromV0_1ToV0_2 = (shape: ShapeModel): ShapeModel => {
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.NORMALTEXT,
textAlignment: 'center',
},
};
case 'smalltext':
Expand All @@ -70,6 +75,7 @@ const mapTextElementFromV0_1ToV0_2 = (shape: ShapeModel): ShapeModel => {
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.SMALLTEXT,
textAlignment: 'center',
},
};
case 'paragraph':
Expand All @@ -78,6 +84,7 @@ const mapTextElementFromV0_1ToV0_2 = (shape: ShapeModel): ShapeModel => {
otherProps: {
...shape,
fontSize: FONT_SIZE_VALUES.PARAGRAPH,
textAlignment: 'center',
},
};
default:
Expand Down
1 change: 1 addition & 0 deletions src/core/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export interface OtherProps {
borderRadius?: string;
activeElement?: number;
selectedBackgroundColor?: string;
textAlignment?: 'left' | 'center' | 'right';
}

export const BASE_ICONS_URL = '/icons/';
Expand Down
7 changes: 7 additions & 0 deletions src/pods/canvas/model/shape-other-props.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const generateDefaultOtherProps = (
fontStyle: `${INPUT_SHAPE.DEFAULT_FONT_STYLE}`,
textDecoration: `${INPUT_SHAPE.DEFAULT_TEXT_DECORATION}`,
fontSize: FONT_SIZE_VALUES.HEADING1,
textAlignment: `${BASIC_SHAPE.DEFAULT_TEXT_ALIGNMENT}`,
};

case 'heading2':
Expand All @@ -135,6 +136,7 @@ export const generateDefaultOtherProps = (
fontStyle: `${INPUT_SHAPE.DEFAULT_FONT_STYLE}`,
textDecoration: `${INPUT_SHAPE.DEFAULT_TEXT_DECORATION}`,
fontSize: FONT_SIZE_VALUES.HEADING2,
textAlignment: `${BASIC_SHAPE.DEFAULT_TEXT_ALIGNMENT}`,
};
case 'heading3':
return {
Expand All @@ -143,12 +145,14 @@ export const generateDefaultOtherProps = (
fontStyle: `${INPUT_SHAPE.DEFAULT_FONT_STYLE}`,
textDecoration: `${INPUT_SHAPE.DEFAULT_TEXT_DECORATION}`,
fontSize: FONT_SIZE_VALUES.HEADING3,
textAlignment: `${BASIC_SHAPE.DEFAULT_TEXT_ALIGNMENT}`,
};
case 'link':
return {
textColor: `${LINK_SHAPE.DEFAULT_FILL_TEXT}`,
textDecoration: 'underline',
fontSize: FONT_SIZE_VALUES.LINK,
textAlignment: `${BASIC_SHAPE.DEFAULT_TEXT_ALIGNMENT}`,
};
case 'normaltext':
return {
Expand All @@ -157,6 +161,7 @@ export const generateDefaultOtherProps = (
fontStyle: `${INPUT_SHAPE.DEFAULT_FONT_STYLE}`,
textDecoration: `${INPUT_SHAPE.DEFAULT_TEXT_DECORATION}`,
fontSize: FONT_SIZE_VALUES.NORMALTEXT,
textAlignment: `${BASIC_SHAPE.DEFAULT_TEXT_ALIGNMENT}`,
};
case 'smalltext':
return {
Expand All @@ -165,10 +170,12 @@ export const generateDefaultOtherProps = (
fontStyle: `${INPUT_SHAPE.DEFAULT_FONT_STYLE}`,
textDecoration: `${INPUT_SHAPE.DEFAULT_TEXT_DECORATION}`,
fontSize: FONT_SIZE_VALUES.SMALLTEXT,
textAlignment: `${BASIC_SHAPE.DEFAULT_TEXT_ALIGNMENT}`,
};
case 'paragraph':
return {
fontSize: FONT_SIZE_VALUES.PARAGRAPH,
textAlignment: `${BASIC_SHAPE.DEFAULT_TEXT_ALIGNMENT}`,
};
case 'label':
return {
Expand Down
1 change: 1 addition & 0 deletions src/pods/properties/components/text-alignment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './text-alignment';
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.container {
display: flex;
align-items: center;
gap: 1.5em;
padding: var(--space-xs) var(--space-md);
border-bottom: 1px solid var(--primary-300);
}

.buttonsContainer {
display: flex;
gap: 1em;
align-items: center;
margin-left: auto;
}

.button {
border: none;
color: var(--text-color);
background-color: inherit;
width: auto;
min-width: 30px;
border-radius: 10px;
font-size: var(--fs-xs);
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease-in-out;
cursor: pointer;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.button:hover {
background-color: var(--primary-100);
}

.active {
background-color: var(--primary-200);
box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
}
Loading