Skip to content

Commit

Permalink
feat: allow overriding of field messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-jonas committed Nov 25, 2024
1 parent a5fcd44 commit 0ea9e8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PropsWithChildren } from "react"
import { cn } from "../../utils/cn"
import { useIntl } from "react-intl"
import {
messageTestId,
OryFormRootProps,
uiTextToFormattedMessage,
useOryFlow,
Expand Down Expand Up @@ -52,11 +53,12 @@ export function DefaultMessage({ message }: OryMessageContentProps) {
const intl = useIntl()
return (
<span
className={cn("text-sm mt-1 leading-normal", {
className={cn("text-sm leading-normal", {
"text-forms-fg-error": message.type === "error",
"text-forms-fg-default": message.type === "info",
"text-forms-fg-success": message.type === "success",
})}
{...messageTestId(message)}
>
{uiTextToFormattedMessage(message, intl)}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
OryNodeLabelProps,
messageTestId,
uiTextToFormattedMessage,
useComponents,
useOryFlow,
} from "@ory/elements-react"
import { useIntl } from "react-intl"
import { cn } from "../../utils/cn"

export function DefaultLabel({
node,
Expand All @@ -19,6 +19,7 @@ export function DefaultLabel({
}: OryNodeLabelProps) {
const intl = useIntl()
const label = getNodeLabel(node)
const { Message } = useComponents()

Check warning on line 22 in packages/elements-react/src/theme/default/components/form/label.tsx

View check run for this annotation

Codecov / codecov/patch

packages/elements-react/src/theme/default/components/form/label.tsx#L22

Added line #L22 was not covered by tests
const { config, flowType, flow } = useOryFlow()

const isPassword = attributes.type === "password"
Expand Down Expand Up @@ -70,17 +71,7 @@ export function DefaultLabel({
)}
{children}
{node.messages.map((message) => (
<span
key={message.id}
className={cn("text-sm leading-normal", {
"text-forms-fg-error": message.type === "error",
"text-forms-fg-default": message.type === "info",
"text-forms-fg-success": message.type === "success",
})}
{...messageTestId(message)}
>
{uiTextToFormattedMessage(message, intl)}
</span>
<Message.Content key={message.id} message={message} />

Check warning on line 74 in packages/elements-react/src/theme/default/components/form/label.tsx

View check run for this annotation

Codecov / codecov/patch

packages/elements-react/src/theme/default/components/form/label.tsx#L74

Added line #L74 was not covered by tests
))}
</div>
)
Expand Down

0 comments on commit 0ea9e8f

Please sign in to comment.