Skip to content

Commit

Permalink
fix(@kadena/react-ui): Update the Notification Component
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmguo authored Nov 20, 2023
2 parents 03b249a + fa59f35 commit 05d6fe3
Show file tree
Hide file tree
Showing 26 changed files with 358 additions and 411 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-buttons-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@kadena/react-ui': minor
---

Updated the Notification component API
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ export const Subscribe: FC = () => {
</form>

{Boolean(message) && (
<Notification.Root color="warning" expanded variant="outlined">
<Notification color="warning" role="status">
{message}
</Notification.Root>
</Notification>
)}
</>
) : (
Boolean(message) && (
<Notification.Root color="positive" expanded variant="outlined">
<Notification color="positive" role="status">
{message}
</Notification.Root>
</Notification>
)
)}
</Stack>
Expand Down
71 changes: 38 additions & 33 deletions packages/apps/docs/src/components/CookieConsent/CookieConsent.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { updateConsent } from '@/utils/analytics';
import { Notification, Text } from '@kadena/react-ui';
import {
Notification,
NotificationButton,
NotificationFooter,
NotificationHeading,
SystemIcon,
Text,
} from '@kadena/react-ui';
import type { FC } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { notificationClass } from './styles.css';
import { containerClass, notificationWrapperClass } from './styles.css';

export const CookieConsent: FC = () => {
const [cookieConsent, setCookieConsent] = useState<boolean | null>(null);
Expand Down Expand Up @@ -31,36 +38,34 @@ export const CookieConsent: FC = () => {
if (cookieConsent !== null || !mounted) return null;

return (
<div className={notificationClass}>
<Notification.Root
title="Cookie Consent"
color="info"
expanded
variant="standard"
icon="Cookie"
>
<Text>
This notification concerns the cookie policy requirement to ask users
for their consent to use <strong>Google Analytics</strong> or other
tracking tools for better optimizations/performances.
</Text>
<Notification.Actions>
<Notification.Button
icon="Check"
color={'positive'}
onClick={handleAccept}
>
Accept
</Notification.Button>
<Notification.Button
icon="Close"
color={'negative'}
onClick={handleReject}
>
Reject
</Notification.Button>
</Notification.Actions>
</Notification.Root>
</div>
<section aria-labelledby="cookie-heading" className={containerClass}>
<div className={notificationWrapperClass}>
<Notification
color="info"
styleVariant="borderless"
icon={<SystemIcon.Cookie />}
role="none"
>
<NotificationHeading id="cookie-heading">
Cookie Consent
</NotificationHeading>
<Text>
This notification concerns the cookie policy requirement to ask
users for their consent to use <strong>Google Analytics</strong> or
other tracking tools for better optimizations/performances.
</Text>
<NotificationFooter>
<NotificationButton color={'positive'} onClick={handleAccept}>
Accept
<SystemIcon.Check />
</NotificationButton>
<NotificationButton color={'negative'} onClick={handleReject}>
Reject
<SystemIcon.Close />
</NotificationButton>
</NotificationFooter>
</Notification>
</div>
</section>
);
};
10 changes: 9 additions & 1 deletion packages/apps/docs/src/components/CookieConsent/styles.css.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { sprinkles } from '@kadena/react-ui/theme';
import { style } from '@vanilla-extract/css';
import { $$pageWidth, globalClass } from '../Layout/global.css';

export const notificationClass = style([
export const containerClass = style([
sprinkles({
position: 'sticky',
top: '$17',
bg: '$primarySurfaceInverted',
}),
{
zIndex: 1000,
},
]);

export const notificationWrapperClass = style([
globalClass,
sprinkles({ marginX: 'auto' }),
{ maxWidth: $$pageWidth },
]);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Notification } from '@kadena/react-ui';
import { Notification, NotificationHeading } from '@kadena/react-ui';
import classNames from 'classnames';
import type { FC, ReactNode } from 'react';
import React from 'react';
Expand All @@ -16,15 +16,15 @@ interface IProps {
export const MDNotification: FC<IProps> = ({ children, title = '', label }) => {
return (
<div className={classNames(wrapperClass, notificationWrapperClass)}>
<Notification.Root
<Notification
color={getColor(label)}
title={title}
expanded
icon={getIcon(label)}
variant="outlined"
styleVariant="borderless"
role="none"
>
<NotificationHeading>{title}</NotificationHeading>
{children}
</Notification.Root>
</Notification>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { INotificationProps } from '@kadena/react-ui';
import { SystemIcon } from '@kadena/react-ui';
import React from 'react';

export type LabelType =
| 'info'
Expand All @@ -7,38 +9,34 @@ export type LabelType =
| 'caution'
| 'danger'
| 'warning';
type IconType = 'Information' | 'Bell' | undefined;

export const getColor = (label?: LabelType): INotificationProps['color'] => {
if (!label) return;
switch (label) {
case 'note':
case 'info':
return 'primary';
case 'tip':
return 'positive';
case 'danger':
case 'warning':
return 'negative';
case 'caution':
return 'warning';
case 'note':
case 'info':
default:
return 'primary';
return 'info';
}
};

export const getIcon = (label?: LabelType): IconType => {
export const getIcon = (label?: LabelType): INotificationProps['icon'] => {
if (!label) return undefined;
switch (label) {
case 'note':
case 'info':
case 'tip':
return 'Information';
case 'caution':
case 'warning':
case 'danger':
return 'Bell';

return <SystemIcon.Bell />;
case 'note':
case 'info':
case 'tip':
default:
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
Button,
Heading,
Notification,
NotificationHeading,
Stack,
SystemIcon,
Tabs,
useModal,
} from '@kadena/react-ui';
Expand Down Expand Up @@ -98,14 +100,13 @@ export const SearchResults: FC<IProps> = ({
</div>
)}
{semanticError ? (
<Notification.Root
<Notification
color={'negative'}
expanded={true}
icon="AlertBox"
variant="outlined"
icon={<SystemIcon.AlertBox />}
role="status"
>
{semanticError}
</Notification.Root>
</Notification>
) : (
<>
<ResultCount count={semanticResults?.length} />
Expand Down Expand Up @@ -136,11 +137,8 @@ export const SearchResults: FC<IProps> = ({

<Tabs.Content id="qa">
<Box marginBottom="$8">
<Notification.Root
expanded={true}
icon="AlertBox"
title="QA search is in beta"
>
<Notification icon={<SystemIcon.AlertBox />} role="none">
<NotificationHeading>QA search is in beta</NotificationHeading>
QA search our latest AI vector-based search, designed to provide
instant answers to your queries.
<br />
Expand All @@ -155,7 +153,7 @@ export const SearchResults: FC<IProps> = ({
collect valuable data that will aid us in refining and enhancing
the accuracy of our model’s responses in the future.
</p>
</Notification.Root>
</Notification>
</Box>
<div className={scrollBoxClasses}>
{isLoading && (
Expand All @@ -164,13 +162,13 @@ export const SearchResults: FC<IProps> = ({
</div>
)}
{error && (
<Notification.Root
<Notification
color={'negative'}
expanded={true}
icon="AlertBox"
icon={<SystemIcon.AlertBox />}
role="status"
>
{error}
</Notification.Root>
</Notification>
)}

{conversation.history?.map((interaction, idx) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ApolloError } from '@apollo/client';
import { Box, Notification } from '@kadena/react-ui';
import { Box, Notification, SystemIcon } from '@kadena/react-ui';
import React from 'react';

interface IErrorBoxProps {
Expand Down Expand Up @@ -28,7 +28,7 @@ export const ErrorBox = (props: IErrorBoxProps): JSX.Element => {
}

return (
<Notification.Root color="negative" icon="Close">
<Notification color="negative" icon={<SystemIcon.Close />} role="status">
{errorTitle}
<Box marginBottom="$4" />
{errorMessage}
Expand All @@ -38,6 +38,6 @@ export const ErrorBox = (props: IErrorBoxProps): JSX.Element => {
<code>{errorExtra}</code>
</>
)}
</Notification.Root>
</Notification>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ const Account: React.FC = () => {
data?.account?.totalBalance === 0 &&
data?.account?.chainAccounts.length === 0 && (
<>
<Notification.Root color="info">
<Notification color="info" role="status">
We could not find any data on this account. Please check the
module and account name.
</Notification.Root>
</Notification>
<Box margin={'$4'} />
</>
)}
Expand Down
29 changes: 18 additions & 11 deletions packages/apps/graph-client/src/pages/transactions/[key].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { useGetTransactionByRequestKeySubscription } from '@/__generated__/sdk';
import LoaderAndError from '@/components/LoaderAndError/loader-and-error';
import routes from '@/constants/routes';
import { formatCode, formatLisp } from '@/utils/formatter';
import { Box, Breadcrumbs, Link, Notification, Table } from '@kadena/react-ui';
import {
Box,
Breadcrumbs,
Link,
Notification,
SystemIcon,
Table,
} from '@kadena/react-ui';
import { useRouter } from 'next/router';
import React from 'react';

Expand Down Expand Up @@ -47,10 +54,10 @@ const RequestKey: React.FC = () => {
</Table.Td>
<Table.Td>
{data?.transaction?.badResult && (
<Notification.Root
<Notification
color="negative"
icon="Close"
variant="outlined"
icon={<SystemIcon.Close />}
role="status"
>
Transaction failed with status:{' '}
<pre>
Expand All @@ -60,24 +67,24 @@ const RequestKey: React.FC = () => {
4,
)}
</pre>
</Notification.Root>
</Notification>
)}
{data?.transaction?.goodResult && (
<Notification.Root
<Notification
color="positive"
icon="Check"
variant="outlined"
icon={<SystemIcon.Check />}
role="status"
>
Transaction succeeded with status:
<br />
<pre>{formatCode(data?.transaction?.goodResult)}</pre>
</Notification.Root>
</Notification>
)}
{!data?.transaction?.goodResult &&
!data?.transaction?.badResult && (
<Notification.Root color="warning" variant="outlined">
<Notification color="warning" role="status">
Unknown transaction status
</Notification.Root>
</Notification>
)}
</Table.Td>
</Table.Tr>
Expand Down
Loading

4 comments on commit 05d6fe3

@vercel
Copy link

@vercel vercel bot commented on 05d6fe3 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

alpha-docs – ./packages/apps/docs

docs.kadena.io
alpha-docs-kadena-js.vercel.app
alpha-docs-git-main-kadena-js.vercel.app
docs-silk-two.vercel.app
alpha-docs.kadena.io

@vercel
Copy link

@vercel vercel bot commented on 05d6fe3 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs-storybook – ./packages/apps/docs

docs-storybook-git-main-kadena-js.vercel.app
docs-storybook-kadena-js.vercel.app
kadena-js-docs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 05d6fe3 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

tools – ./packages/apps/tools

kadena-js-transfer.vercel.app
tools-git-main-kadena-js.vercel.app
tools.kadena.io
tools-kadena-js.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 05d6fe3 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-ui – ./packages/libs/react-ui

react-ui-git-main-kadena-js.vercel.app
react-ui-delta.vercel.app
react-ui-kadena-js.vercel.app
react-ui.kadena.io

Please sign in to comment.