From b67918d7a04d93bc00737470232fc3f5a1a2c655 Mon Sep 17 00:00:00 2001 From: Joanna Date: Wed, 3 Apr 2024 15:40:04 +0200 Subject: [PATCH 1/3] fix: styles update --- package-lock.json | 15 ++++ package.json | 1 + .../UserHubButton/UserHubButton.tsx | 5 +- .../MemberReputation/MemberReputation.tsx | 4 +- .../shared/Extensions/Tooltip/Tooltip.tsx | 2 + .../shared/Extensions/Tooltip/types.ts | 1 + .../partials/PermissionSidebar.tsx | 2 +- .../ExitRecoveryStep/ExitRecoveryStep.tsx | 39 +++++----- .../steps/FinalizeStep/FinalizeStep.tsx | 2 +- .../Motions/steps/OutcomeStep/OutcomeStep.tsx | 10 ++- .../Motions/steps/OutcomeStep/hooks.ts | 49 ++++++++++++ .../partials/VoteStatuses/VoteStatuses.tsx | 10 +-- .../Motions/steps/RevealStep/RevealStep.tsx | 76 ++++++++++++------- .../Motions/steps/StakingStep/StakingStep.tsx | 4 +- .../Motions/steps/VotingStep/VotingStep.tsx | 63 +++++++++------ .../Motions/steps/VotingStep/hooks.tsx | 1 + .../partials/ProgressContent.tsx | 2 +- .../v5/common/ObjectiveBox/ObjectiveBox.tsx | 5 +- .../partials/Objective/Objective.tsx | 3 +- .../MenuWithStatusText/MenuWithStatusText.tsx | 10 +-- .../v5/shared/ProgressBar/ProgressBar.tsx | 19 ++--- src/components/v5/shared/ProgressBar/types.ts | 3 +- .../v5/shared/StatusText/StatusText.tsx | 9 ++- src/components/v5/shared/Stepper/Stepper.tsx | 47 +++++++++--- .../partials/StepperButton/StepperButton.tsx | 12 ++- src/i18n/en.json | 5 +- src/stories/shared/ProgressBar.stories.tsx | 14 ---- 27 files changed, 275 insertions(+), 138 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5e8d20ca77c..6d36260d25c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -79,6 +79,7 @@ "react-helmet-async": "^2.0.3", "react-hook-form": "^7.45.2", "react-hooks-visible": "^1.1.1", + "react-intersection-observer": "^9.8.2", "react-intl": "^6.6.1", "react-modal": "^3.15.1", "react-popper": "^2.3.0", @@ -45606,6 +45607,20 @@ "react": ">=16.8" } }, + "node_modules/react-intersection-observer": { + "version": "9.8.2", + "resolved": "https://registry.npmjs.org/react-intersection-observer/-/react-intersection-observer-9.8.2.tgz", + "integrity": "sha512-901naEiiZmse3p+AmtbQ3NL9xx+gQ8TXLiGDc+8GiE3JKJkNV3vP737aGuWTAXBA+1QqxPrDDE+fIEgYpGDlrQ==", + "peerDependencies": { + "react": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0", + "react-dom": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0" + }, + "peerDependenciesMeta": { + "react-dom": { + "optional": true + } + } + }, "node_modules/react-intl": { "version": "6.6.1", "license": "BSD-3-Clause", diff --git a/package.json b/package.json index 33fde5a48a5..0b145c8f61b 100644 --- a/package.json +++ b/package.json @@ -211,6 +211,7 @@ "react-helmet-async": "^2.0.3", "react-hook-form": "^7.45.2", "react-hooks-visible": "^1.1.1", + "react-intersection-observer": "^9.8.2", "react-intl": "^6.6.1", "react-modal": "^3.15.1", "react-popper": "^2.3.0", diff --git a/src/components/common/Extensions/UserHubButton/UserHubButton.tsx b/src/components/common/Extensions/UserHubButton/UserHubButton.tsx index b7b19487ad3..4aaa429fccf 100644 --- a/src/components/common/Extensions/UserHubButton/UserHubButton.tsx +++ b/src/components/common/Extensions/UserHubButton/UserHubButton.tsx @@ -141,7 +141,7 @@ const UserHubButton: FC = () => { splitWalletAddress(walletAddress ?? ADDRESS_ZERO); return ( -
+
{fileSize} - + ); diff --git a/src/components/v5/common/ObjectiveBox/ObjectiveBox.tsx b/src/components/v5/common/ObjectiveBox/ObjectiveBox.tsx index 13af4e79676..6f74a8ff27f 100644 --- a/src/components/v5/common/ObjectiveBox/ObjectiveBox.tsx +++ b/src/components/v5/common/ObjectiveBox/ObjectiveBox.tsx @@ -37,7 +37,10 @@ const ObjectiveBox: FC = ({ objective }) => { ) : formatMessage(MSG.noObjectiveBoxDescription)}

- + ); }; diff --git a/src/components/v5/frame/ColonyHome/partials/Objective/Objective.tsx b/src/components/v5/frame/ColonyHome/partials/Objective/Objective.tsx index 99b4ab3caeb..64e9bcc336d 100644 --- a/src/components/v5/frame/ColonyHome/partials/Objective/Objective.tsx +++ b/src/components/v5/frame/ColonyHome/partials/Objective/Objective.tsx @@ -53,8 +53,7 @@ const Objective = () => {

diff --git a/src/components/v5/shared/MenuWithStatusText/MenuWithStatusText.tsx b/src/components/v5/shared/MenuWithStatusText/MenuWithStatusText.tsx index 89c72aa293b..a0edbc30b75 100644 --- a/src/components/v5/shared/MenuWithStatusText/MenuWithStatusText.tsx +++ b/src/components/v5/shared/MenuWithStatusText/MenuWithStatusText.tsx @@ -10,8 +10,6 @@ const displayName = 'v5.shared.MenuWithStatusText'; const MenuWithStatusText: React.FC = ({ statusTextSectionProps, sections, - footer, - footerClassName, }) => { const { content, ...restStatusTextSectionProps } = statusTextSectionProps; @@ -29,13 +27,7 @@ const MenuWithStatusText: React.FC = ({ ...sections, ]; - return ( - - ); + return ; }; MenuWithStatusText.displayName = displayName; diff --git a/src/components/v5/shared/ProgressBar/ProgressBar.tsx b/src/components/v5/shared/ProgressBar/ProgressBar.tsx index 16015d393c9..6f6f605f334 100644 --- a/src/components/v5/shared/ProgressBar/ProgressBar.tsx +++ b/src/components/v5/shared/ProgressBar/ProgressBar.tsx @@ -5,19 +5,20 @@ import { type ProgressBarProps } from './types.ts'; const ProgressBar: FC = ({ progress, + progressLabel, isTall, - additionalText, threshold = null, max = 100, barClassName, className, + labelClassName, }) => { if (progress > max || progress < 0) { throw new Error(`Progress bar value must be between between 0 and ${max}`); } return ( -
+
= ({ /> )}
- - {progress} + + {progressLabel || progress} - {additionalText && ( - - {additionalText} - - )}
); }; diff --git a/src/components/v5/shared/ProgressBar/types.ts b/src/components/v5/shared/ProgressBar/types.ts index bd2108b0fd3..79a30d40266 100644 --- a/src/components/v5/shared/ProgressBar/types.ts +++ b/src/components/v5/shared/ProgressBar/types.ts @@ -1,9 +1,10 @@ export interface ProgressBarProps { progress: number; + progressLabel?: string; isTall?: boolean; - additionalText?: React.ReactNode; threshold?: number; max?: number; barClassName?: string; className?: string; + labelClassName?: string; } diff --git a/src/components/v5/shared/StatusText/StatusText.tsx b/src/components/v5/shared/StatusText/StatusText.tsx index 4b3c949eca5..fed9beda42a 100644 --- a/src/components/v5/shared/StatusText/StatusText.tsx +++ b/src/components/v5/shared/StatusText/StatusText.tsx @@ -30,7 +30,7 @@ const StatusText: FC> = ({ return (
> = ({ className={clsx(iconClassName, 'flex-shrink-0')} /> )} -

{children}

+ {children && typeof children === 'string' && ( +

{children}

+ )} + {children && typeof children !== 'string' && ( +
{children}
+ )}
); }; diff --git a/src/components/v5/shared/Stepper/Stepper.tsx b/src/components/v5/shared/Stepper/Stepper.tsx index c2aa3a2d749..7cd9f906e54 100644 --- a/src/components/v5/shared/Stepper/Stepper.tsx +++ b/src/components/v5/shared/Stepper/Stepper.tsx @@ -2,6 +2,7 @@ import { CaretLeft, CaretRight } from '@phosphor-icons/react'; import clsx from 'clsx'; import { motion } from 'framer-motion'; import React, { useEffect, useState } from 'react'; +import { InView } from 'react-intersection-observer'; import { accordionAnimation } from '~constants/accordionAnimation.ts'; import { useMobile } from '~hooks/index.ts'; @@ -19,6 +20,7 @@ function Stepper({ items, }: StepperProps): JSX.Element | null { const activeItemIndex = items.findIndex(({ key }) => key === activeStepKey); + const [hiddenItem, setHiddenItem] = useState(undefined); const [openItemIndex, setOpenItemIndex] = useState(activeItemIndex); const isMobile = useMobile(); const openedItem = items[openItemIndex]; @@ -47,14 +49,14 @@ function Stepper({ } }; - useEffect(() => { - const handleResize = () => { - const element = listRef.current; - if (element) { - setIsScrollableList(element.scrollWidth > element.clientWidth); - } - }; + const handleResize = () => { + const element = listRef.current; + if (element) { + setIsScrollableList(element.scrollWidth > element.clientWidth); + } + }; + useEffect(() => { handleResize(); window.addEventListener('resize', handleResize); @@ -66,8 +68,30 @@ function Stepper({ useEffect(() => { setOpenItemIndex(activeItemIndex); + handleResize(); }, [activeItemIndex]); + const handleChange = (name: TKey, inView: boolean) => { + if (!inView) { + setHiddenItem(name); + } else { + setHiddenItem(undefined); + } + }; + + useEffect(() => { + if (hiddenItem && listRef.current && isMobile && isScrollableList) { + const index = items.findIndex(({ key }) => key === hiddenItem); + if (index > -1) { + listRef.current.scrollBy({ + left: 70 * index, + behavior: 'smooth', + }); + } + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [openItemIndex, isMobile]); + return items.length ? ( <>
@@ -145,7 +169,11 @@ function Stepper({ }, )} > -
+ handleChange(key, inView)} + className="flex flex-col items-start gap-[.375rem] sm:flex-row sm:items-center" + > ({ } onClick={() => { setOpenItemIndex(index); + setHiddenItem(undefined); if (index > activeItemIndex && setActiveStepKey) { setActiveStepKey(key); @@ -168,7 +197,7 @@ function Stepper({ {...restHeading} /> {decor || null} -
+ {!isMobile && !itemDisabled && !!content && (
= ({ ...rest }) => { const { ref, scroll } = useScrollIntoView(); + const [buttonWidth, setButtonWidth] = useState(0); const Icon = icon || ICON_NAME_MAP[stage]; const isMobile = useMobile(); + useEffect(() => { + if (ref.current) { + setButtonWidth(ref.current.offsetWidth); + } + }, []); + useEffect(() => { if (isHighlighted) { scroll({ behavior: 'smooth', inline: 'end' }); @@ -83,8 +90,9 @@ const StepperButton: React.FC = ({ ) : ( {content} diff --git a/src/i18n/en.json b/src/i18n/en.json index d85a87d30b3..1c3ad550fc4 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -1387,8 +1387,7 @@ "motion.revealStep.title": "You voted:", "motion.revealStep.statusText": "Ends when timer ends; or all voters have revealed.", "motion.revealStep.warning": "You must reveal your vote for it to count and to claim your reward.", - "motion.revealStep.votesRevealed": "votes revealed", - "motion.revealStep.voteRevealed": "vote revealed", + "motion.revealStep.votesRevealed": "{votes} {votes, plural, one {vote} other {votes}} revealed", "motion.revealStep.submit": "Reveal vote", "motion.revealStep.buttonHide": "Hide reveal information", "motion.revealStep.buttonShow": "Show reveal information", @@ -1396,7 +1395,7 @@ "motion.revealStep.emptyDescription": "You did not vote so do not need to reveal. Please wait for all required voters to reveal or the reveal stage to end.", "motion.votingStep.statusText": "Voting ends when either time runs out, or {thresholdPercent}% of reputation in this domain has voted.", "motion.votingStep.title": "Vote to support or oppose?", - "motion.votingStep.additionalText": "% Rep", + "motion.votingStep.additionalText": "{progress}% Rep", "motion.votingStep.votingMethod": "Voting method", "motion.votingStep.teamReputation": "Team reputation", "motion.votingStep.rewardRange": "Reward range", diff --git a/src/stories/shared/ProgressBar.stories.tsx b/src/stories/shared/ProgressBar.stories.tsx index bf34d5c06ab..17a8efa07d1 100644 --- a/src/stories/shared/ProgressBar.stories.tsx +++ b/src/stories/shared/ProgressBar.stories.tsx @@ -24,12 +24,6 @@ const meta: Meta = { type: 'range', }, }, - additionalText: { - name: 'Additional text', - control: { - type: 'text', - }, - }, isTall: { name: 'Is tall?', control: { @@ -53,11 +47,3 @@ export const WithData: Story = { progress: 40, }, }; - -export const WithAdditionalText: Story = { - args: { - progress: 50, - additionalText: 'Rep', - isTall: true, - }, -}; From 0eb10b07479e9cd0f6955a8b47f2b3dd4a774952 Mon Sep 17 00:00:00 2001 From: Cezary Dryl Date: Thu, 27 Jun 2024 11:19:36 +0200 Subject: [PATCH 2/3] fix: tooltip position --- .../ActionSidebar/partials/Motions/Motions.tsx | 12 ++++++------ .../Stepper/partials/StepperButton/StepperButton.tsx | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/v5/common/ActionSidebar/partials/Motions/Motions.tsx b/src/components/v5/common/ActionSidebar/partials/Motions/Motions.tsx index 398c641d61d..c826315ad32 100644 --- a/src/components/v5/common/ActionSidebar/partials/Motions/Motions.tsx +++ b/src/components/v5/common/ActionSidebar/partials/Motions/Motions.tsx @@ -1,6 +1,6 @@ import { MotionState as NetworkMotionState } from '@colony/colony-js'; import { ThumbsDown, ThumbsUp } from '@phosphor-icons/react'; -import { left as LeftPlacementType } from '@popperjs/core'; +import { right as RightPlacementType } from '@popperjs/core'; import clsx from 'clsx'; import { BigNumber } from 'ethers'; import React, { type FC, useEffect, useMemo, useState } from 'react'; @@ -114,7 +114,7 @@ const Motions: FC = ({ transactionId }) => { networkMotionState, motionData, ), - placement: LeftPlacementType, + placement: RightPlacementType, className: 'z-10', }, }, @@ -145,7 +145,7 @@ const Motions: FC = ({ transactionId }) => { networkMotionState, motionData, ), - placement: LeftPlacementType, + placement: RightPlacementType, className: 'z-10', }, }, @@ -180,7 +180,7 @@ const Motions: FC = ({ transactionId }) => { networkMotionState, motionData, ), - placement: LeftPlacementType, + placement: RightPlacementType, className: 'z-10', }, }, @@ -244,7 +244,7 @@ const Motions: FC = ({ transactionId }) => { networkMotionState, motionData, ), - placement: LeftPlacementType, + placement: RightPlacementType, className: 'z-10', }, }, @@ -269,7 +269,7 @@ const Motions: FC = ({ transactionId }) => { networkMotionState, motionData, ), - placement: LeftPlacementType, + placement: RightPlacementType, className: 'z-10', }, }, diff --git a/src/components/v5/shared/Stepper/partials/StepperButton/StepperButton.tsx b/src/components/v5/shared/Stepper/partials/StepperButton/StepperButton.tsx index bbb4436b3d9..ee2dd21a7c2 100644 --- a/src/components/v5/shared/Stepper/partials/StepperButton/StepperButton.tsx +++ b/src/components/v5/shared/Stepper/partials/StepperButton/StepperButton.tsx @@ -31,7 +31,7 @@ const StepperButton: React.FC = ({ if (ref.current) { setButtonWidth(ref.current.offsetWidth); } - }, []); + }, [ref]); useEffect(() => { if (isHighlighted) { From 359249cdbc37f2cbaade9b26343133cec4447405 Mon Sep 17 00:00:00 2001 From: Cezary Dryl Date: Mon, 1 Jul 2024 15:39:44 +0200 Subject: [PATCH 3/3] fix: remove useEffect, progressLabel prop --- .../Motions/steps/RevealStep/RevealStep.tsx | 21 +++++++++++-------- .../Motions/steps/VotingStep/VotingStep.tsx | 21 +++++++++++-------- .../v5/shared/ProgressBar/ProgressBar.tsx | 8 +------ src/components/v5/shared/ProgressBar/types.ts | 3 +-- .../partials/StepperButton/StepperButton.tsx | 17 +++++++-------- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/components/v5/common/ActionSidebar/partials/Motions/steps/RevealStep/RevealStep.tsx b/src/components/v5/common/ActionSidebar/partials/Motions/steps/RevealStep/RevealStep.tsx index dcaf446972a..499f9412dda 100644 --- a/src/components/v5/common/ActionSidebar/partials/Motions/steps/RevealStep/RevealStep.tsx +++ b/src/components/v5/common/ActionSidebar/partials/Motions/steps/RevealStep/RevealStep.tsx @@ -80,15 +80,18 @@ const RevealStep: FC = ({ + {formatText( + { + id: 'motion.revealStep.votesRevealed', + }, + { + votes: revealProgress, + }, + )} + + } max={totalVoters} isTall /> diff --git a/src/components/v5/common/ActionSidebar/partials/Motions/steps/VotingStep/VotingStep.tsx b/src/components/v5/common/ActionSidebar/partials/Motions/steps/VotingStep/VotingStep.tsx index 28a6cf6226f..5cb42616738 100644 --- a/src/components/v5/common/ActionSidebar/partials/Motions/steps/VotingStep/VotingStep.tsx +++ b/src/components/v5/common/ActionSidebar/partials/Motions/steps/VotingStep/VotingStep.tsx @@ -81,15 +81,18 @@ const VotingStep: FC = ({ className="mt-2" progress={currentReputationPercent} threshold={thresholdPercent} - labelClassName="!text-xs" - progressLabel={formatText( - { - id: 'motion.votingStep.additionalText', - }, - { - progress: currentReputationPercent, - }, - )} + progressLabel={ + + {formatText( + { + id: 'motion.votingStep.additionalText', + }, + { + progress: currentReputationPercent, + }, + )} + + } isTall />
diff --git a/src/components/v5/shared/ProgressBar/ProgressBar.tsx b/src/components/v5/shared/ProgressBar/ProgressBar.tsx index 6f6f605f334..925fc20d4a1 100644 --- a/src/components/v5/shared/ProgressBar/ProgressBar.tsx +++ b/src/components/v5/shared/ProgressBar/ProgressBar.tsx @@ -11,7 +11,6 @@ const ProgressBar: FC = ({ max = 100, barClassName, className, - labelClassName, }) => { if (progress > max || progress < 0) { throw new Error(`Progress bar value must be between between 0 and ${max}`); @@ -43,12 +42,7 @@ const ProgressBar: FC = ({ /> )}
- + {progressLabel || progress}
diff --git a/src/components/v5/shared/ProgressBar/types.ts b/src/components/v5/shared/ProgressBar/types.ts index 79a30d40266..5f69781fc49 100644 --- a/src/components/v5/shared/ProgressBar/types.ts +++ b/src/components/v5/shared/ProgressBar/types.ts @@ -1,10 +1,9 @@ export interface ProgressBarProps { progress: number; - progressLabel?: string; + progressLabel?: JSX.Element | string; isTall?: boolean; threshold?: number; max?: number; barClassName?: string; className?: string; - labelClassName?: string; } diff --git a/src/components/v5/shared/Stepper/partials/StepperButton/StepperButton.tsx b/src/components/v5/shared/Stepper/partials/StepperButton/StepperButton.tsx index ee2dd21a7c2..b4f54a19ecc 100644 --- a/src/components/v5/shared/Stepper/partials/StepperButton/StepperButton.tsx +++ b/src/components/v5/shared/Stepper/partials/StepperButton/StepperButton.tsx @@ -1,5 +1,5 @@ import clsx from 'clsx'; -import React, { useEffect, useState } from 'react'; +import React, { useEffect } from 'react'; import { useMobile } from '~hooks'; import { useScrollIntoView } from '~hooks/useScrollIntoView.ts'; @@ -23,16 +23,9 @@ const StepperButton: React.FC = ({ ...rest }) => { const { ref, scroll } = useScrollIntoView(); - const [buttonWidth, setButtonWidth] = useState(0); const Icon = icon || ICON_NAME_MAP[stage]; const isMobile = useMobile(); - useEffect(() => { - if (ref.current) { - setButtonWidth(ref.current.offsetWidth); - } - }, [ref]); - useEffect(() => { if (isHighlighted) { scroll({ behavior: 'smooth', inline: 'end' }); @@ -92,7 +85,13 @@ const StepperButton: React.FC = ({ {content}