| 1 |
import { useState } from "@wordpress/element"; |
| 2 |
import { Spacing, SpColorPicker, SPRangeControl, SPToggleGroupControl, Toggle, TypographyNew } from "../../components"; |
| 3 |
import { __ } from "@wordpress/i18n"; |
| 4 |
export const ExcerptTab = ({ attributes, setAttributes }) => { |
| 5 |
const [colorState, setColorState] = useState("normal"); |
| 6 |
const { |
| 7 |
blockName, |
| 8 |
excerptMargin, |
| 9 |
excerptShow, |
| 10 |
excerptLineHeight, |
| 11 |
excerptLatterSpacing, |
| 12 |
excerptFontSize, |
| 13 |
excerptTypography, |
| 14 |
excerptColor, |
| 15 |
excerptLength, |
| 16 |
excerptWordSpacing, |
| 17 |
excerptGlobalTypography, |
| 18 |
} = attributes; |
| 19 |
|
| 20 |
return ( |
| 21 |
<> |
| 22 |
<Toggle |
| 23 |
label={__("Show Excerpt", "post-carousel")} |
| 24 |
attributes={excerptShow} |
| 25 |
attributesKey={"excerptShow"} |
| 26 |
setAttributes={setAttributes} |
| 27 |
/> |
| 28 |
|
| 29 |
{excerptShow && ( |
| 30 |
<> |
| 31 |
<SPRangeControl |
| 32 |
label={__("Excerpt Length", "post-carousel")} |
| 33 |
attributes={excerptLength} |
| 34 |
attributesKey={"excerptLength"} |
| 35 |
setAttributes={setAttributes} |
| 36 |
units={[]} |
| 37 |
defaultValue={{ |
| 38 |
unit: "words", |
| 39 |
value: 10, |
| 40 |
}} |
| 41 |
max={200} |
| 42 |
className="sp-smart-post-ranger-length" |
| 43 |
/> |
| 44 |
|
| 45 |
<TypographyNew |
| 46 |
attributes={{ |
| 47 |
family: excerptTypography, |
| 48 |
familyKey: "excerptTypography", |
| 49 |
fontSize: excerptFontSize, |
| 50 |
fontSizeKey: "excerptFontSize", |
| 51 |
fontSpacing: excerptLatterSpacing, |
| 52 |
fontSpacingKey: "excerptLatterSpacing", |
| 53 |
lineHeight: excerptLineHeight, |
| 54 |
lineHeightKey: "excerptLineHeight", |
| 55 |
wordSpacing: excerptWordSpacing, |
| 56 |
wordSpacingKey: "excerptWordSpacing", |
| 57 |
globalTypo: excerptGlobalTypography, |
| 58 |
globalTypoKey: "excerptGlobalTypography", |
| 59 |
}} |
| 60 |
setAttributes={setAttributes} |
| 61 |
spacingDefaultValue={{ unit: "px", value: 0 }} |
| 62 |
fontSizeDefault={{ |
| 63 |
unit: "px", |
| 64 |
value: 14, |
| 65 |
}} |
| 66 |
lineDefaultValue={1.2} |
| 67 |
typographyLabel={ |
| 68 |
blockName === "taxonomy" |
| 69 |
? __("Typography", "post-carousel") |
| 70 |
: __("Typography", "post-carousel") |
| 71 |
} |
| 72 |
/> |
| 73 |
|
| 74 |
<SPToggleGroupControl |
| 75 |
attributes={colorState} |
| 76 |
items={[ |
| 77 |
{ label: "Normal", value: "normal" }, |
| 78 |
{ label: "Hover", value: "hover" }, |
| 79 |
]} |
| 80 |
onClick={(newColor) => setColorState(newColor)} |
| 81 |
/> |
| 82 |
{"normal" === colorState ? ( |
| 83 |
<SpColorPicker |
| 84 |
label={__("Color", "post-carousel")} |
| 85 |
value={excerptColor.color} |
| 86 |
onChange={(newColor) => |
| 87 |
setAttributes({ |
| 88 |
excerptColor: { |
| 89 |
...excerptColor, |
| 90 |
color: newColor, |
| 91 |
}, |
| 92 |
}) |
| 93 |
} |
| 94 |
defaultColor="#FFFFFF" |
| 95 |
/> |
| 96 |
) : ( |
| 97 |
<SpColorPicker |
| 98 |
label={__("Color", "post-carousel")} |
| 99 |
value={excerptColor.hoverColor} |
| 100 |
onChange={(newColor) => |
| 101 |
setAttributes({ |
| 102 |
excerptColor: { |
| 103 |
...excerptColor, |
| 104 |
hoverColor: newColor, |
| 105 |
}, |
| 106 |
}) |
| 107 |
} |
| 108 |
/> |
| 109 |
)} |
| 110 |
<Spacing |
| 111 |
label={__("Margin", "post-carousel")} |
| 112 |
attributes={excerptMargin} |
| 113 |
attributesKey={"excerptMargin"} |
| 114 |
setAttributes={setAttributes} |
| 115 |
units={["px", "%", "em"]} |
| 116 |
defaultValue={{ |
| 117 |
unit: "px", |
| 118 |
value: { |
| 119 |
top: "0", |
| 120 |
right: "0", |
| 121 |
bottom: "0", |
| 122 |
left: "0", |
| 123 |
}, |
| 124 |
}} |
| 125 |
/> |
| 126 |
</> |
| 127 |
)} |
| 128 |
</> |
| 129 |
); |
| 130 |
}; |
| 131 |
|