diff --git a/src/pages/setting/personality/components/ButtonSidebar.tsx b/src/pages/setting/personality/components/ButtonSidebar.tsx index 0e785fb..54cc5ff 100644 --- a/src/pages/setting/personality/components/ButtonSidebar.tsx +++ b/src/pages/setting/personality/components/ButtonSidebar.tsx @@ -19,9 +19,9 @@ const ButtonSidebar: FC = () => { const [buttonSize, setButtonSize] = useState(ButtonSize.MEDIUM) const [isBorder, setIsBorder] = useState(false) const [borderSize, setBorderSize] = useState(1) - const [textColor, setTextColor] = useState('#000') + const [textColor, setTextColor] = useState('#fff') const [backgroundColor, setBackgroundColor] = useState('#000') - const [borderColor, setBorderColor] = useState('#000') + const [borderColor, setBorderColor] = useState('#fff') const [horizontalAlignment, setHorizontalAlignment] = useState(HorizontalAlignment.CENTER) const [verticalAlignment, setVerticalAlignment] = useState(VerticalAlignment.MIDDLE) @@ -51,9 +51,9 @@ const ButtonSidebar: FC = () => { setButtonSize(ButtonSize.MEDIUM) setIsBorder(false) setBorderSize(1) - setTextColor('#000') + setTextColor('#fff') setBackgroundColor('#000') - setBorderColor('#000') + setBorderColor('#fff') setHorizontalAlignment(HorizontalAlignment.CENTER) setVerticalAlignment(VerticalAlignment.MIDDLE) } diff --git a/src/pages/setting/personality/components/ImageRenderer.tsx b/src/pages/setting/personality/components/ImageRenderer.tsx index 4f3f1ba..f6f7056 100644 --- a/src/pages/setting/personality/components/ImageRenderer.tsx +++ b/src/pages/setting/personality/components/ImageRenderer.tsx @@ -8,80 +8,135 @@ interface ImageRendererProps { const ImageRenderer: FC = ({ images }) => { if (!images || images.length === 0) return null + // تابع‌های helper برای تبدیل enum به string + const getHorizontalAlign = (alignment?: HorizontalAlignment) => { + switch (alignment) { + case HorizontalAlignment.LEFT: + return 'left' + case HorizontalAlignment.RIGHT: + return 'right' + case HorizontalAlignment.CENTER: + default: + return 'center' + } + } + + const getVerticalAlign = (verticalAlignment?: VerticalAlignment) => { + switch (verticalAlignment) { + case VerticalAlignment.TOP: + return 'top' + case VerticalAlignment.BOTTOM: + return 'bottom' + case VerticalAlignment.MIDDLE: + default: + return 'middle' + } + } + + const getImageStyle = (image: ImageType) => { + return { + width: image.width || '100%', + height: image.height || 'auto', + border: '0' + } + } + + const shouldUseBackgroundImage = (imageSize: ImageSize) => { + return imageSize === ImageSize.REPEAT || + imageSize === ImageSize.REPEAT_X || + imageSize === ImageSize.REPEAT_Y + } + const getBackgroundStyle = (image: ImageType) => { - let backgroundSize = 'cover' let backgroundRepeat = 'no-repeat' switch (image.size) { - case ImageSize.COVER: - backgroundSize = 'cover' - backgroundRepeat = 'no-repeat' - break - case ImageSize.CONTAIN: - backgroundSize = 'contain' - backgroundRepeat = 'no-repeat' - break case ImageSize.REPEAT: - backgroundSize = 'auto' backgroundRepeat = 'repeat' break case ImageSize.REPEAT_X: - backgroundSize = 'auto' backgroundRepeat = 'repeat-x' break case ImageSize.REPEAT_Y: - backgroundSize = 'auto' backgroundRepeat = 'repeat-y' break - case ImageSize.NO_REPEAT: - backgroundSize = 'auto' - backgroundRepeat = 'no-repeat' - break - case ImageSize.AUTO: default: - backgroundSize = 'auto' backgroundRepeat = 'no-repeat' break } - let backgroundPosition = 'center center' - - // تنظیم موقعیت بر اساس alignment const horizontal = image.alignment === HorizontalAlignment.LEFT ? 'left' : image.alignment === HorizontalAlignment.RIGHT ? 'right' : 'center' const vertical = image.verticalAlignment === VerticalAlignment.TOP ? 'top' : image.verticalAlignment === VerticalAlignment.BOTTOM ? 'bottom' : 'center' - backgroundPosition = `${horizontal} ${vertical}` - return { backgroundImage: `url(${image.src})`, - backgroundSize, + backgroundPosition: `${horizontal} ${vertical}`, backgroundRepeat, - backgroundPosition, width: image.width || '100%', - height: image.height || '60px', - display: 'block' + height: image.height || '100px' } } + const renderImage = (image: ImageType) => { + if (shouldUseBackgroundImage(image.size)) { + // برای pattern های repeat از background استفاده می‌کنیم + return ( +
+   +
+ ) + } + + // برای تصاویر عادی + if (image.size === ImageSize.CONTAIN) { + // برای contain از table wrapper استفاده می‌کنیم تا نسبت حفظ شود + return ( + + + + + + +
+ {image.alt +
+ ) + } + + // برای cover و auto + return ( + {image.alt + ) + } + return ( <> {images.map((image, imageIndex) => ( - +
diff --git a/src/pages/setting/personality/components/ImageSideBar.tsx b/src/pages/setting/personality/components/ImageSideBar.tsx index a9cf89b..bfff861 100644 --- a/src/pages/setting/personality/components/ImageSideBar.tsx +++ b/src/pages/setting/personality/components/ImageSideBar.tsx @@ -133,19 +133,16 @@ const ImageSideBar: FC = () => {
setHorizontalAlignment(HorizontalAlignment.RIGHT)} >
setHorizontalAlignment(HorizontalAlignment.CENTER)} >
setHorizontalAlignment(HorizontalAlignment.LEFT)} > @@ -159,19 +156,16 @@ const ImageSideBar: FC = () => {
setVerticalAlignment(VerticalAlignment.BOTTOM)} >
setVerticalAlignment(VerticalAlignment.MIDDLE)} >
setVerticalAlignment(VerticalAlignment.TOP)} > diff --git a/src/pages/setting/personality/components/SettingSideBar.tsx b/src/pages/setting/personality/components/SettingSideBar.tsx index 8f7ff13..a3489e7 100644 --- a/src/pages/setting/personality/components/SettingSideBar.tsx +++ b/src/pages/setting/personality/components/SettingSideBar.tsx @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next' import UploadBoxDraggble from '@/components/UploadBoxDraggble'; import ColorPicker from '@/components/ColorPicker'; import { usePersonalityStore } from '../store/Store'; -import { SectionItemType, BackgroundSize } from '../types/Types'; +import { SectionItemType, BackgroundSize, SectionName } from '../types/Types'; import Select from '@/components/Select'; const SettingSideBar: FC = () => { @@ -19,10 +19,10 @@ const SettingSideBar: FC = () => { const bgSize = style.backgroundSize const bgRepeat = style.backgroundRepeat - if (bgSize === BackgroundSize.COVER) return BackgroundSize.COVER - if (bgSize === BackgroundSize.CONTAIN) return BackgroundSize.CONTAIN + if (bgSize === 'cover') return BackgroundSize.COVER + if (bgSize === 'contain') return BackgroundSize.CONTAIN if (bgSize === 'auto' || !bgSize) { - if (bgRepeat === BackgroundSize.ROUND) return BackgroundSize.ROUND + if (bgRepeat === 'round') return BackgroundSize.ROUND } return BackgroundSize.COVER } @@ -40,7 +40,7 @@ const SettingSideBar: FC = () => { const handleColumnClick = (columns: number) => { if (activeSection) { - setColumnsCount(activeSection as "header" | "content" | "footer", columns); + setColumnsCount(activeSection as SectionName, columns); } }
-
- {/* محتوا درون div با background image */} -   -
+ {renderImage(image)}