Skip to content

Commit 184cca8

Browse files
committed
feat: add the ability to center the text in paragraphs
1 parent 86e7923 commit 184cca8

File tree

11 files changed

+43
-30
lines changed

11 files changed

+43
-30
lines changed

packages/keybr-multiplayer-ui/lib/Connector.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ClientCodec } from "@keybr/multiplayer-shared";
2-
import { Article, Para, styleTextCenter } from "@keybr/widget";
2+
import { Article, Para } from "@keybr/widget";
33
import { type ReactNode, useMemo } from "react";
44
import { FormattedMessage } from "react-intl";
55
import { Game } from "./Game.tsx";
@@ -39,7 +39,7 @@ function useTransport() {
3939

4040
function Banner(): ReactNode {
4141
return (
42-
<Para className={styleTextCenter}>
42+
<Para align="center">
4343
<FormattedMessage
4444
id="multiplayer.intro.description"
4545
defaultMessage="Compete against other players in this online multiplayer game. The faster you type, the faster your car goes. Type as fast as you can to win the race!"

packages/keybr-widget/lib/components/text/Para.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { clsx } from "clsx";
22
import { type ReactNode } from "react";
3+
import { alignClassName } from "../../styles/index.ts";
34
import * as styles from "./Para.module.less";
45
import { type ParaProps } from "./Para.types.ts";
56

67
export function Para(props: ParaProps): ReactNode {
7-
const { as: Component = "p", id, title, className, children } = props;
8+
const { as: Component = "p", id, title, className, children, align } = props;
89
return (
9-
<Component id={id} className={clsx(styles.root, className)} title={title}>
10+
<Component
11+
id={id}
12+
className={clsx(styles.root, alignClassName(align), className)}
13+
title={title}
14+
>
1015
{children}
1116
</Component>
1217
);

packages/keybr-widget/lib/components/text/Para.types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type ElementType, type HTMLAttributes, type ReactNode } from "react";
2+
import { type AlignName } from "../../styles/index.ts";
23
import { type ClassName } from "../types.ts";
34

45
export type ParaProps = {
@@ -7,4 +8,5 @@ export type ParaProps = {
78
readonly id?: string;
89
readonly title?: string;
910
readonly children?: ReactNode;
11+
readonly align?: AlignName;
1012
};

packages/keybr-widget/lib/styles/size.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export type SizeName =
2323
| 24
2424
| 32;
2525

26-
export const sizeClassName = (size?: SizeName | null): ClassName => {
27-
switch (size) {
26+
export const sizeClassName = (value?: SizeName | null): ClassName => {
27+
switch (value) {
2828
case "fill":
2929
return styleSizeFill;
3030
case "fillAlt":
+15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
1+
import { type ClassName } from "../components/index.ts";
12
import * as styles from "./text.module.less";
23

34
export const styleTextCenter = styles.textCenter;
45
export const styleTextStart = styles.textStart;
56
export const styleTextEnd = styles.textEnd;
67
export const styleTextNoWrap = styles.textNoWrap;
78
export const styleTextTruncate = styles.textTruncate;
9+
10+
export type AlignName = "start" | "center" | "end";
11+
12+
export const alignClassName = (value?: AlignName | null): ClassName => {
13+
switch (value) {
14+
case "start":
15+
return styleTextStart;
16+
case "center":
17+
return styleTextCenter;
18+
case "end":
19+
return styleTextEnd;
20+
}
21+
return null;
22+
};

packages/page-practice/lib/practice/LearningRateDescription.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useIntlNumbers } from "@keybr/intl";
22
import { type LearningRate, type LessonKey } from "@keybr/lesson";
3-
import { Name, Para, styleTextCenter, Value } from "@keybr/widget";
3+
import { Name, Para, Value } from "@keybr/widget";
44
import { type ReactNode } from "react";
55
import { FormattedMessage } from "react-intl";
66

@@ -14,7 +14,7 @@ export function LearningRateDescription({
1414
const { formatNumber, formatPercents } = useIntlNumbers();
1515
if ((lessonKey.bestConfidence ?? 0) >= 1) {
1616
return (
17-
<Para className={styleTextCenter}>
17+
<Para align="center">
1818
<Name>
1919
<FormattedMessage
2020
id="learningRate.alreadyUnlocked"
@@ -30,7 +30,7 @@ export function LearningRateDescription({
3030
learningRate.certainty > 0
3131
) {
3232
return (
33-
<Para className={styleTextCenter}>
33+
<Para align="center">
3434
<Name>
3535
<FormattedMessage
3636
id="learningRate.remainingLessons"
@@ -52,7 +52,7 @@ export function LearningRateDescription({
5252
);
5353
}
5454
return (
55-
<Para className={styleTextCenter}>
55+
<Para align="center">
5656
<Name>
5757
<FormattedMessage
5858
id="learningRate.unknown"

packages/page-profile/lib/profile/AccuracyHistogramSection.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
Figure,
88
Para,
99
RadioBox,
10-
styleTextCenter,
1110
Value,
1211
} from "@keybr/widget";
1312
import React, { type ReactNode, useMemo, useState } from "react";
@@ -49,7 +48,7 @@ export function AccuracyHistogramSection({
4948
</Figure.Description>
5049
</Explainer>
5150

52-
<Para className={styleTextCenter}>
51+
<Para align="center">
5352
{period === "average" ? (
5453
<FormattedMessage
5554
id="profile.chart.compareAverageAccuracy.description"

packages/page-profile/lib/profile/AccuracyStreaksSection.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@ import {
55
MutableStreakList,
66
type Streak,
77
} from "@keybr/result";
8-
import {
9-
Explainer,
10-
Figure,
11-
NameValue,
12-
Para,
13-
styleTextCenter,
14-
} from "@keybr/widget";
8+
import { Explainer, Figure, NameValue, Para } from "@keybr/widget";
159
import { type ReactNode } from "react";
1610
import { FormattedMessage, useIntl } from "react-intl";
1711
import { type ResultSummary } from "./resultsummary.ts";
@@ -39,7 +33,7 @@ export function AccuracyStreaksSection({
3933
))}
4034
</dl>
4135
) : (
42-
<Para className={styleTextCenter}>
36+
<Para align="center">
4337
<FormattedMessage
4438
id="profile.accuracy.noData"
4539
defaultMessage="You don’t have any accuracy streaks. Consider completing a lesson with a highest accuracy possible, regardless of typing speed."

packages/page-profile/lib/profile/KeySpeedChartSection.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { KeyDetails, KeySelector } from "@keybr/lesson-ui";
44
import { hasData } from "@keybr/math";
55
import { type KeyStatsMap } from "@keybr/result";
66
import { useSettings } from "@keybr/settings";
7-
import { Explainer, Figure, Para, styleTextCenter } from "@keybr/widget";
7+
import { Explainer, Figure, Para } from "@keybr/widget";
88
import { type ReactNode, useState } from "react";
99
import { FormattedMessage } from "react-intl";
1010
import { ChartWrapper } from "./ChartWrapper.tsx";
@@ -47,7 +47,7 @@ export function KeySpeedChartSection({
4747
</Figure.Description>
4848
</Explainer>
4949

50-
<Para className={styleTextCenter}>
50+
<Para align="center">
5151
<KeySelector
5252
keyStatsMap={keyStatsMap}
5353
current={current}
@@ -57,7 +57,7 @@ export function KeySpeedChartSection({
5757
/>
5858
</Para>
5959

60-
<Para className={styleTextCenter}>
60+
<Para align="center">
6161
<KeyDetails lessonKey={LessonKey.from(keyStats, target)} />
6262
</Para>
6363

packages/page-profile/lib/profile/SpeedHistogramSection.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
Figure,
88
Para,
99
RadioBox,
10-
styleTextCenter,
1110
Value,
1211
} from "@keybr/widget";
1312
import React, { type ReactNode, useMemo, useState } from "react";
@@ -49,7 +48,7 @@ export function SpeedHistogramSection({
4948
</Figure.Description>
5049
</Explainer>
5150

52-
<Para className={styleTextCenter}>
51+
<Para align="center">
5352
{period === "average" ? (
5453
<FormattedMessage
5554
id="profile.chart.compareAverageSpeed.description"

packages/page-typing-test/lib/components/Report.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
NameValue,
1919
Para,
2020
Spacer,
21-
styleTextCenter,
2221
useHotkeys,
2322
Value,
2423
} from "@keybr/widget";
@@ -64,7 +63,7 @@ export const Report = memo(function Report({
6463
/>
6564
</Box>
6665

67-
<Para className={styleTextCenter}>
66+
<Para align="center">
6867
<NameValue name="Characters" value={formatNumber(length)} />
6968
<NameValue name="Errors" value={formatNumber(errors)} />
7069
<NameValue
@@ -82,7 +81,7 @@ export const Report = memo(function Report({
8281
/>
8382
</Box>
8483

85-
<Para className={styleTextCenter}>
84+
<Para align="center">
8685
<Name>
8786
Faster than <Value value={formatPercents(pSpeed)} /> of all other
8887
people.
@@ -101,7 +100,7 @@ export const Report = memo(function Report({
101100
/>
102101
</Box>
103102

104-
<Para className={styleTextCenter}>
103+
<Para align="center">
105104
<Name>
106105
More accurate than <Value value={formatPercents(pAccuracy)} /> of all
107106
other people.
@@ -128,7 +127,7 @@ export const Report = memo(function Report({
128127
<Field.Filler />
129128
</FieldList>
130129

131-
<Para className={styleTextCenter}>
130+
<Para align="center">
132131
Press <Kbd>Enter</Kbd> to start a new test.
133132
</Para>
134133
</Screen>

0 commit comments

Comments
 (0)