Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ui): migrate Message component to Typescript #511

Merged
merged 28 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bd29884
chore(ui): convert Message to typescript
guoda-puidokaite Oct 10, 2024
b96be9f
chore(ui): changeset
guoda-puidokaite Oct 10, 2024
b4121bf
chore(ui): comment improvements
guoda-puidokaite Oct 10, 2024
693ea5d
Merge branch 'main' into guoda-convert-message-to-ts
guoda-puidokaite Oct 10, 2024
dee0a8a
Merge branch 'main' into guoda-convert-message-to-ts
andypf Oct 10, 2024
6d20504
chore(ui): fix bug, add tests and update comments
guoda-puidokaite Oct 10, 2024
70045d0
chore(ui): move back externalised css, icon and timeout logic to main…
guoda-puidokaite Oct 10, 2024
ea0bcee
chore(ui): organise tests and add zero/negative timeout test
guoda-puidokaite Oct 10, 2024
ddb6b97
chore(ui): update changelog
guoda-puidokaite Oct 10, 2024
7a311e7
chore(ui): revert test and allow arbitrary props
guoda-puidokaite Oct 10, 2024
bdc86cb
chore(ui): remove redundant comment
guoda-puidokaite Oct 10, 2024
cc725e9
Merge branch 'main' into guoda-convert-message-to-ts
guoda-puidokaite Oct 11, 2024
ab9b7a6
chore(ui): make Message consistent with Badge
guoda-puidokaite Oct 11, 2024
d736343
chore(ui): update comments and names to have consistency with Message…
guoda-puidokaite Oct 11, 2024
aaf538e
chore(ui): move to vitest
guoda-puidokaite Oct 11, 2024
2bff147
chore(ui): allow object to be set as children in storybook and revert…
guoda-puidokaite Oct 11, 2024
21ba073
chore(ui): revert some changes
guoda-puidokaite Oct 11, 2024
3e25bf7
Merge branch 'main' into guoda-convert-message-to-ts
guoda-puidokaite Oct 11, 2024
ac04ac5
chore(ui): small tweaks
guoda-puidokaite Oct 11, 2024
4e39aa7
chore(ui): tidy code
guoda-puidokaite Oct 11, 2024
9ddaa83
chore(ui): remove incorrect storybook control for children
guoda-puidokaite Oct 14, 2024
60cfdb0
chore(ui): disable incorrect object control for children in storybook
guoda-puidokaite Oct 14, 2024
e2c5ce9
Merge branch 'main' into guoda-convert-message-to-ts
guoda-puidokaite Oct 15, 2024
4b5276d
chore(ui): make suggested changes
guoda-puidokaite Oct 15, 2024
94a6248
chore(ui): fix test
guoda-puidokaite Oct 15, 2024
7e410d0
Merge branch 'main' into guoda-convert-message-to-ts
guoda-puidokaite Oct 15, 2024
0d0d79e
chore(ui): rename variant type
guoda-puidokaite Oct 15, 2024
7f5411a
Merge branch 'main' into guoda-convert-message-to-ts
andypf Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/hungry-panthers-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudoperators/juno-ui-components": minor
---

Migrate Message component to TypeScript
216 changes: 0 additions & 216 deletions packages/ui-components/src/components/Message/Message.component.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useEffect, useState, useRef } from "react"

import { Icon } from "../Icon"

import { MessageProps } from "./Message.types"
import { getMuiIcon } from "./utils/iconUtils"
andypf marked this conversation as resolved.
Show resolved Hide resolved
import { initiateAutoDismiss, clearAutoDismissTimeout } from "./utils/timeoutUtils"
andypf marked this conversation as resolved.
Show resolved Hide resolved
import {
andypf marked this conversation as resolved.
Show resolved Hide resolved
messageStyles,
messageBorderStyles,
messageContentStyles,
messageHeadingStyles,
dismissButtonStyles,
getBackgroundClass,
getVariantClass,
} from "./utils/cssUtils"

export const Message: React.FC<MessageProps> = ({
title = "",
text = "",
variant = "info",
dismissible = false,
autoDismiss = false,
autoDismissTimeout = 10000,
onDismiss,
className = "",
children,
...props
}) => {
const [visible, setVisible] = useState<boolean>(true)
const autoDismissTimeoutRef = useRef<number | null>(null)

const hideMessage = () => {
setVisible(false)
onDismiss && onDismiss()
}

useEffect(() => {
// Clean timeout on component unmount
return () => {
clearAutoDismissTimeout(autoDismissTimeoutRef)
}
}, [])

// Hide message after passed or preconfigured timeout if autoDismiss is true
useEffect(() => {
initiateAutoDismiss(autoDismiss, autoDismissTimeout, hideMessage, autoDismissTimeoutRef)
}, [autoDismiss, autoDismissTimeout])

if (!visible) return null

return (
<div
className={`juno-message juno-message-${variant} ${messageStyles} ${getBackgroundClass(variant)} ${className}`}
{...props}
>
<div className={`juno-message-border ${messageBorderStyles} ${getVariantClass(variant)}`}></div>
<Icon icon={getMuiIcon(variant)} color={`jn-text-theme-${variant}`} className="jn-shrink-0" />
<div className={`juno-message-content ${messageContentStyles}`}>
{title && <h1 className={messageHeadingStyles}>{title}</h1>}
<div>{children || text}</div>
</div>
{dismissible && (
<div className={dismissButtonStyles}>
<Icon
icon="close"
onClick={hideMessage}
className="juno-message-close-button jn-opacity-50 hover:jn-opacity-100"
/>
</div>
)}
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { Message } from "./index.js"
import { Message } from "./index"

export default {
title: "Components/Message",
Expand Down
Loading
Loading