Skip to content

Commit

Permalink
add label template to donation goal widget
Browse files Browse the repository at this point in the history
  • Loading branch information
stCarolas committed Jun 19, 2024
1 parent 16da4f9 commit 794df0f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FontProperty } from "../widgetproperties/FontProperty";
import { NumberProperty } from "../widgetproperties/NumberProperty";
import { ColorProperty } from "../widgetproperties/ColorProperty";
import { SingleChoiceProperty } from "../widgetproperties/SingleChoiceProperty";
import { TextProperty } from "../widgetproperties/TextProperty";

export class DonationGoalWidgetSettings extends AbstractWidgetSettings {
constructor(widgetId: string, properties: WidgetProperty[]) {
Expand Down Expand Up @@ -99,6 +100,14 @@ export class DonationGoalWidgetSettings extends AbstractWidgetSettings {
["left", "center", "right"],
"header",
),
new TextProperty(
widgetId,
"labelTemplate",
"predefined",
"<collected> / <required> <currency>",
"widget-donationgoal-label-template",
"header"
),
new DonationGoalProperty(widgetId),
],
tabs,
Expand Down
21 changes: 17 additions & 4 deletions src/components/DonationGoal/DonationGoal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export default function DonationGoal({}) {
const font = findSetting(settings, "titleFont", "Alice");
const textColor = findSetting(settings, "titleColor", "black");
const titleTextAlign = findSetting(settings, "titleTextAlign", "left");
const labelTemplate = findSetting(
settings,
"labelTemplate",
"<collected> / <required> <currency>",
);
const textStyle = {
fontSize: fontSize ? fontSize + "px" : "unset",
fontFamily: font ? font : "unset",
Expand All @@ -78,7 +83,7 @@ export default function DonationGoal({}) {
const filledFontSize = findSetting(settings, "filledFontSize", "24");
const filledFont = findSetting(settings, "filledFont", "Russo One");
let filledTextAlign = findSetting(settings, "filledTextAlign", "left");
switch(filledTextAlign){
switch (filledTextAlign) {
case "left":
filledTextAlign = "flex-start";
break;
Expand All @@ -90,7 +95,7 @@ export default function DonationGoal({}) {
fontSize: filledFontSize ? filledFontSize + "px" : "unset",
fontFamily: filledFont ? filledFont : "unset",
color: filledTextColor,
justifyContent: filledTextAlign
justifyContent: filledTextAlign,
};

return (
Expand All @@ -104,7 +109,7 @@ export default function DonationGoal({}) {
{goal.briefDescription}
</div>
<div
style={ progressbarStyle }
style={progressbarStyle}
className={`${classes.goalprogressbar}`}
></div>
<div
Expand All @@ -118,7 +123,15 @@ export default function DonationGoal({}) {
className={`${classes.goalfilled}`}
></div>
<div style={filledTextStyle} className={`${classes.goalamount}`}>
{goal.accumulatedAmount.major} / {goal.requiredAmount.major} RUB
{labelTemplate
.replaceAll("<collected>", goal.accumulatedAmount.major)
.replaceAll("<required>", goal.requiredAmount.major)
.replaceAll("<currency>", "RUB")
.replaceAll(
"<proportion>",
(goal.accumulatedAmount.major / goal.requiredAmount.major) *
100,
)}
</div>
</div>
</>
Expand Down
2 changes: 2 additions & 0 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ i18n
"widget-donationgoal-background":"Background color",
"widget-donationgoal-filled-color":"Filled part color",
"widget-donationgoal-amount-alignment":"Amount alignment",
"widget-donationgoal-label-template":"Label template",
"widget-goal-title":"Title",
"widget-goal-description":"Description",
"widget-goal-amount":"Amount",
Expand Down Expand Up @@ -236,6 +237,7 @@ i18n
"widget-donationgoal-background":"Цвет фона полоски",
"widget-donationgoal-filled-color":"Цвет заполненной части",
"widget-donationgoal-amount-alignment":"Выравнивание суммы",
"widget-donationgoal-label-template":"Шаблон надписи",
"widget-goal-title":"Название",
"widget-goal-description":"Описание",
"widget-goal-amount":"Сумма",
Expand Down

0 comments on commit 794df0f

Please sign in to comment.