Skip to content

Commit c81325f

Browse files
committed
refactor: move static options out of config (for appearance)
1 parent 5584b9b commit c81325f

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

frontend/app/components/redesign/components/AppearanceBuilder.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,12 @@ import {
3030
SLIDE_ANIMATION
3131
} from '@shared/types'
3232

33+
export interface AppearanceOptions {
34+
showThumbnail: boolean
35+
fontSizeRange: { min: number; max: number; default: number }
36+
}
37+
3338
interface BaseToolAppearance {
34-
fontSizeRange: { min: number; max: number }
3539
fontName?: FontFamilyKey
3640
fontSize?: number
3741
backgroundColor?: string
@@ -66,8 +70,8 @@ export interface WidgetToolAppearance extends BaseToolAppearance {
6670
export type ToolAppearance = BannerToolAppearance | WidgetToolAppearance
6771

6872
interface AppearanceBuilderProps {
69-
toolName: 'widget' | 'banner'
7073
config: ToolAppearance
74+
options: AppearanceOptions
7175
onRefresh: () => void
7276
positionSelector?: React.ReactNode
7377
colorsSelector?: React.ReactNode
@@ -80,13 +84,13 @@ function getValidSlideAnimation(value: unknown): SlideAnimationType {
8084
}
8185

8286
export const AppearanceBuilder: React.FC<AppearanceBuilderProps> = ({
83-
toolName,
8487
config,
88+
options,
8589
onRefresh,
8690
positionSelector,
8791
colorsSelector
8892
}) => {
89-
const { min: minFontSize, max: maxFontSize } = config.fontSizeRange
93+
const { min: minFontSize, max: maxFontSize } = options.fontSizeRange
9094

9195
const [selectedThumbnail, setSelectedThumbnail] = useState(0)
9296
const { actions: uiActions, state: uiState } = useUI()
@@ -258,7 +262,7 @@ export const AppearanceBuilder: React.FC<AppearanceBuilderProps> = ({
258262

259263
<div
260264
className={cx(
261-
toolName === 'widget' ? 'hidden' : 'flex flex-col gap-xs'
265+
options.showThumbnail ? 'flex flex-col gap-xs' : 'hidden'
262266
)}
263267
>
264268
<Divider />

frontend/app/components/redesign/components/BuilderForm.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ import { toolState, toolActions, type StableKey } from '~/stores/toolStore'
88
import { useUI } from '~/stores/uiStore'
99
import { useSnapshot } from 'valtio'
1010
import type { ContentOptions, ToolContent } from './ContentBuilder'
11-
import type { ToolAppearance } from './AppearanceBuilder'
11+
import type { AppearanceOptions, ToolAppearance } from './AppearanceBuilder'
1212

1313
interface BuilderFormProps {
1414
config: ToolContent | ToolAppearance
15-
options: ContentOptions
16-
toolName: 'widget' | 'banner'
15+
options: ContentOptions | AppearanceOptions
1716
onRefresh: (section: 'appearance' | 'content') => void
1817
onBuildStepComplete?: (isComplete: boolean) => void
1918
positionSelector?: React.ReactNode
@@ -25,7 +24,6 @@ export const BuilderForm: React.FC<BuilderFormProps> = ({
2524
onRefresh,
2625
config,
2726
options,
28-
toolName,
2927
positionSelector,
3028
colorsSelector
3129
}) => {
@@ -76,14 +74,14 @@ export const BuilderForm: React.FC<BuilderFormProps> = ({
7674
<ContentBuilder
7775
onRefresh={() => onRefresh('content')}
7876
config={config as ToolContent}
79-
options={options}
77+
options={options as ContentOptions}
8078
/>
8179
<AppearanceBuilder
8280
onRefresh={() => onRefresh('appearance')}
8381
config={config as ToolAppearance}
82+
options={options as AppearanceOptions}
8483
positionSelector={positionSelector}
8584
colorsSelector={colorsSelector}
86-
toolName={toolName}
8785
/>
8886
</BuilderPresetTabs>
8987
</div>

frontend/app/routes/banner.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ import type {
4646
ContentOptions,
4747
ToolContent
4848
} from '~/components/redesign/components/ContentBuilder'
49-
import type { BannerToolAppearance } from '~/components/redesign/components/AppearanceBuilder'
49+
import type {
50+
AppearanceOptions,
51+
BannerToolAppearance
52+
} from '~/components/redesign/components/AppearanceBuilder'
5053
import { BANNER_FONT_SIZES } from '@shared/types'
5154
import type {
5255
BannerPositionKey,
@@ -180,7 +183,7 @@ const BannerPreview = React.forwardRef<BannerHandle>((props, ref) => {
180183

181184
BannerPreview.displayName = 'BannerPreview'
182185

183-
const contentOptions: ContentOptions = {
186+
const options: ContentOptions | AppearanceOptions = {
184187
suggestedTitles: [
185188
'How to support?',
186189
'Fund me',
@@ -193,7 +196,10 @@ const contentOptions: ContentOptions = {
193196
messageLabel: 'Banner message',
194197
messagePlaceholder: 'Enter your banner message...',
195198
messageHelpText: 'Strong message to help people engage with Web Monetization',
196-
messageMaxLength: 300
199+
messageMaxLength: 300,
200+
201+
showThumbnail: true,
202+
fontSizeRange: BANNER_FONT_SIZES
197203
}
198204

199205
export default function Banner() {
@@ -225,7 +231,6 @@ export default function Banner() {
225231

226232
fontName: snap.currentConfig?.bannerFontName,
227233
fontSize: snap.currentConfig?.bannerFontSize ?? BANNER_FONT_SIZES.default,
228-
fontSizeRange: BANNER_FONT_SIZES,
229234
backgroundColor: snap.currentConfig?.bannerBackgroundColor,
230235
textColor: snap.currentConfig?.bannerTextColor,
231236
borderRadius: snap.currentConfig?.bannerBorder,
@@ -392,9 +397,8 @@ export default function Banner() {
392397
/>
393398

394399
<BuilderForm
395-
toolName="banner"
396400
config={config}
397-
options={contentOptions}
401+
options={options}
398402
onBuildStepComplete={(isComplete) =>
399403
toolActions.setBuildCompleteStep(
400404
isComplete ? 'filled' : 'unfilled'

frontend/app/routes/widget.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ import type {
4343
ContentOptions,
4444
ToolContent
4545
} from '~/components/redesign/components/ContentBuilder'
46-
import type { WidgetToolAppearance } from '~/components/redesign/components/AppearanceBuilder'
46+
import type {
47+
AppearanceOptions,
48+
WidgetToolAppearance
49+
} from '~/components/redesign/components/AppearanceBuilder'
4750
import { WIDGET_FONT_SIZES } from '@shared/types'
4851
import type {
4952
CornerType,
@@ -168,7 +171,7 @@ const WidgetPreview: React.FC = () => {
168171
)
169172
}
170173

171-
const options: ContentOptions = {
174+
const options: ContentOptions | AppearanceOptions = {
172175
suggestedTitles: [
173176
'Support this content',
174177
'Make a payment',
@@ -181,7 +184,10 @@ const options: ContentOptions = {
181184
messageLabel: 'Widget message',
182185
messagePlaceholder: 'Enter your widget message...',
183186
messageHelpText: 'Describe how payments support your work',
184-
messageMaxLength: 300
187+
messageMaxLength: 300,
188+
189+
showThumbnail: false,
190+
fontSizeRange: WIDGET_FONT_SIZES
185191
}
186192

187193
export default function Widget() {
@@ -212,7 +218,6 @@ export default function Widget() {
212218

213219
fontName: snap.currentConfig?.widgetFontName,
214220
fontSize: snap.currentConfig?.widgetFontSize ?? WIDGET_FONT_SIZES.default,
215-
fontSizeRange: WIDGET_FONT_SIZES,
216221
backgroundColor: snap.currentConfig?.widgetBackgroundColor,
217222
textColor: snap.currentConfig?.widgetTextColor,
218223
buttonColor: snap.currentConfig?.widgetButtonBackgroundColor,
@@ -376,7 +381,6 @@ export default function Widget() {
376381
/>
377382

378383
<BuilderForm
379-
toolName="widget"
380384
config={config}
381385
options={options}
382386
onBuildStepComplete={(isComplete) =>

0 commit comments

Comments
 (0)