Skip to content

🎥 Make videos programmatically with React

`@remotion/promo-pages`: Fix pricing compnent

Jonny Burgera8e74c5a1119
diff --git a/packages/design/src/Counter.tsx b/packages/design/src/Counter.tsx
index e6287a4989..ad2610796a 100644
--- a/packages/design/src/Counter.tsx
+++ b/packages/design/src/Counter.tsx
@@ -43,38 +43,48 @@ const buttonContainer: React.CSSProperties = {
interface CounterProps {
readonly count: number;
readonly setCount: (count: number) => void;
- readonly minCount?: number;
- readonly step?: number;
+ readonly minCount: number;
+ readonly step: number;
+ readonly incrementStep: number;
}
+const MAX_COUNT = 9999999;
+
export const Counter: React.FC<CounterProps> = ({
count,
setCount,
- minCount = 0,
- step = 1,
+ minCount,
+ step,
+ incrementStep,
}) => {
const decrement = () => {
if (count > minCount) {
- setCount(Math.max(minCount, count - step));
+ setCount(Math.max(minCount, count - incrementStep));
}
};
const increment = () => {
- setCount(count + step);
+ const nextValue = count + incrementStep;
+ const roundedValue = Math.round(nextValue / incrementStep) * incrementStep;
+
+ setCount(Math.min(MAX_COUNT, roundedValue));
};
+ const shrink = String(count).length > 6;
+
return (
<Card
style={container}
className={cn('w-[140px] flex flex-row overflow-hidden')}
>
<input
- className={
- 'fontbrand text-2xl font-medium min-w-[80px] border-0 text-end outline-0 text-text overflow-hidden flex-1 px-0 py-0 pr-2 w-full h-full tabular-nums'
- }
+ className={cn(
+ 'fontbrand font-medium min-w-[80px] border-0 text-end outline-0 text-text overflow-hidden flex-1 px-0 py-0 pr-2 w-full h-full tabular-nums',
+ shrink ? 'text-lg' : 'text-2xl',
+ )}
type="number"
- onClick={(e) => e.currentTarget.select()}
value={count}
+ onClick={(e) => e.currentTarget.select()}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
if (e.target.value.trim() === '') {
setCount(step === 1 ? 1 : minCount);
@@ -82,7 +92,10 @@ export const Counter: React.FC<CounterProps> = ({
}
const inputValue = parseInt(e.target.value, 10);
- const validValue = Math.max(inputValue, minCount);
+ const validValue = Math.min(
+ MAX_COUNT,
+ Math.max(inputValue, minCount),
+ );
// For steps > 1, round to the nearest valid step
if (step > 1) {
diff --git a/packages/promo-pages/src/components/homepage/FreePricing.tsx b/packages/promo-pages/src/components/homepage/FreePricing.tsx
index 58cdb485ab..2a4031bf70 100644
--- a/packages/promo-pages/src/components/homepage/FreePricing.tsx
+++ b/packages/promo-pages/src/components/homepage/FreePricing.tsx
@@ -60,13 +60,15 @@ const PriceTag: React.FC<{
};
const SmallPriceTag: React.FC<{
- readonly children: React.ReactNode;
+ readonly children: string;
}> = ({children}) => {
+ const shrink = children.length > 6;
return (
<div
- className={
- 'fontbrand text-2xl font-medium w-auto min-w-[80px] text-right shrink-0'
- }
+ className={cn(
+ 'fontbrand text-2xl font-medium w-auto min-w-[100px] text-right shrink-0',
+ shrink ? 'text-lg' : 'text-2xl',
+ )}
>
{children}
</div>
@@ -171,7 +173,8 @@ export const CompanyPricing: React.FC = () => {
const totalPrice = useMemo(() => {
return Math.max(
100,
- devSeatCount * SEAT_PRICE + (cloudRenders / 1000) * RENDER_UNIT_PRICE,
+ devSeatCount * SEAT_PRICE +
+ Math.ceil(cloudRenders / 1000) * RENDER_UNIT_PRICE,
);
}, [cloudRenders, devSeatCount]);
@@ -203,12 +206,13 @@ export const CompanyPricing: React.FC = () => {
count={devSeatCount}
setCount={setDevSeatCount}
minCount={1}
+ incrementStep={1}
+ step={1}
/>
<SmallPriceTag>
- $
- {new Intl.NumberFormat('en-US', {
+ {`$${new Intl.NumberFormat('en-US', {
maximumFractionDigits: 0,
- }).format(SEAT_PRICE * devSeatCount)}
+ }).format(SEAT_PRICE * devSeatCount)}`}
</SmallPriceTag>
</div>
</div>
@@ -231,13 +235,13 @@ export const CompanyPricing: React.FC = () => {
count={cloudRenders}
setCount={setCloudRenders}
minCount={0}
- step={1000}
+ step={1}
+ incrementStep={1000}
/>
<SmallPriceTag>
- $
- {new Intl.NumberFormat('en-US', {
+ {`$${new Intl.NumberFormat('en-US', {
maximumFractionDigits: 0,
- }).format((cloudRenders / 1000) * RENDER_UNIT_PRICE)}
+ }).format(Math.ceil(cloudRenders / 1000) * RENDER_UNIT_PRICE)}`}
</SmallPriceTag>
</div>
</div>