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

coreui NoteBox component #1276

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
47 changes: 47 additions & 0 deletions packages/libs/coreui/src/components/containers/NoteBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { css } from '@emotion/react';
import React, { ReactNode } from 'react';
import { error, warning, mutedBlue } from '../../definitions/colors';

export interface Props {
type: 'info' | 'warning' | 'error';
children: ReactNode;
}

const baseCss = css`
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps additionally a default font? I believe coreui generally uses Inter or Roboto

Copy link
Member Author

Choose a reason for hiding this comment

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

For content, I think we should use the same font as the rest of the site, but I will take a look at using one of these other fonts.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I'm going to leave the font as-is.

border-left: 0.25em solid var(--note-box-border-color);
Copy link
Member

Choose a reason for hiding this comment

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

ive never seen this before. That's very slick

border-radius: 0.25em;
padding: 0.5em 1em;
background: var(--note-box-bg-color);
gap: 1em;
margin-bottom: 1em;
`;

const infoCss = css`
--note-box-bg-color: ${mutedBlue[100]};
--note-box-border-color: ${mutedBlue[600]};
${baseCss};
`;

const warningCss = css`
--note-box-bg-color: ${warning[100]};
--note-box-border-color: ${warning[600]};
font-weight: 500;
${baseCss};
`;

const errorCss = css`
--note-box-bg-color: ${error[100]};
--note-box-border-color: ${error[600]};
font-weight: 500;
${baseCss};
`;

export function NoteBox(props: Props) {
const finalCss =
props.type === 'warning'
? warningCss
: props.type === 'error'
? errorCss
: infoCss;
return <div css={finalCss}>{props.children}</div>;
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps for later, but it'd be nice to pair the icon with the NoteBox type. We picked one icon for error, warning, and info ( a looong time ago and i think it was never actually impllemented). Of course, one could pass that as part of the child, but if we want to keep coreui very opinionated then there could be a useIcon prop and if that is true. the appropriate icon for that NoteBox style appears.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed!

}
1 change: 1 addition & 0 deletions packages/libs/coreui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export { default as SelectTree } from './components/inputs/SelectTree/SelectTree
export { default as SearchBox } from './components/inputs/SearchBox/SearchBox';
export { default as CheckboxList } from './components/inputs/checkboxes/CheckboxList';
export { default as CheckboxTree } from './components/inputs/checkboxes/CheckboxTree/CheckboxTree';
export { NoteBox } from './components/containers/NoteBox';

export { default as styles } from './styleDefinitions';
export { default as colors } from './definitions/colors';
Expand Down
74 changes: 74 additions & 0 deletions packages/libs/coreui/src/stories/containers/NoteBox.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
import { NoteBox, Props } from '../../components/containers/NoteBox';
import { Story, Meta } from '@storybook/react/types-6-0';
import { UIThemeProvider } from '../../components/theming';
import { mutedGreen, mutedMagenta } from '../../definitions/colors';

export default {
title: 'Containers/NoteBox',
component: NoteBox,
} as Meta;

const Template: Story<Props> = function Template(props) {
return (
<UIThemeProvider
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to add the theme here? Or is it just to check that we get the correct colors regardless of theme?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was just following the same pattern as another story file (can't remember which one). I guess we could take it out, but not sure it hurts?

theme={{
palette: {
primary: { hue: mutedGreen, level: 500 },
secondary: { hue: mutedMagenta, level: 500 },
},
}}
>
<NoteBox {...props} />
</UIThemeProvider>
);
};

export const Info = Object.assign(Template.bind({}), {
args: {
type: 'info',
children: (
<div>
This is some general information about the content that follows on the
page.
</div>
),
},
});

export const Warning = Object.assign(Template.bind({}), {
args: {
type: 'warning',
children: (
<div>This is a warning about the content that follows on the page.</div>
),
},
});

export const Error = Object.assign(Template.bind({}), {
args: {
type: 'error',
children: (
<div>
This is an error message about the content that follows on the page.
</div>
),
},
});

export const LongContent = Object.assign(Template.bind({}), {
args: {
type: 'info',
children: (
<div>
Lorem ipsum odor amet, consectetuer adipiscing elit. Faucibus morbi ac
ultrices purus urna tristique mattis consequat. Posuere volutpat
facilisi natoque dictumst dignissim magna dapibus. Taciti vel a etiam
curabitur velit torquent. Fusce interdum dictum vulputate sollicitudin
nulla. Orci placerat congue odio aptent enim mauris. Turpis nec rhoncus
eleifend eleifend eget. Auctor sed nullam vestibulum quisque egestas;
nullam aenean ante.
</div>
),
},
});
Copy link
Member

Choose a reason for hiding this comment

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

A story using a different type of child (for example, an image or some other non-text element) would be helpful if time allows

Copy link
Member

Choose a reason for hiding this comment

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

or an expandable one

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I agree! I will add a couple more, soon.

Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import PropTypes from 'prop-types';
import React, { useState } from 'react';
import { safeHtml, wrappable } from '../../../Utils/ComponentUtils';

const containerStyle = {
display: 'flex',
flexWrap: 'wrap',
borderLeft: '.2em solid #79a3d7',
borderRight: '.2em solid #79a3d7',
padding: '.5em 1em',
background: '#ebf4ff',
gap: '1em',
marginBottom: '1em',
};
import { NoteBox } from '@veupathdb/coreui';

function RecordTableDescription(props) {
const { description } = props.table;
Expand All @@ -21,7 +11,7 @@ function RecordTableDescription(props) {
if (!description) return null;

return (
<div style={containerStyle}>
<NoteBox type="info">
{safeHtml(
description,
{
Expand All @@ -30,7 +20,7 @@ function RecordTableDescription(props) {
return;
}
if (
el.clientWidth >= el.scrollWidth ||
el.clientWidth >= el.scrollWidth &&
el.clientHeight >= el.scrollHeight
) {
setIsOverflowing(false);
Expand All @@ -51,15 +41,23 @@ function RecordTableDescription(props) {
'div'
)}
{isOverflowing && (
<button
type="button"
className="link"
onClick={() => setIsExpanded((value) => !value)}
>
{isExpanded ? 'Read less' : 'Read more'}
</button>
<>
<button
type="button"
style={{
border: 'none',
padding: 0,
margin: '1ex 0 0 0',
background: 'transparent',
color: '#069',
}}
onClick={() => setIsExpanded((value) => !value)}
>
{isExpanded ? 'Read less' : 'Read more'}
</button>
</>
)}
</div>
</NoteBox>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { PfamDomain } from 'ortho-client/components/pfam-domains/PfamDomain';
import {
FilledButton,
FloatingButton,
NoteBox,
OutlinedButton,
SelectList,
Undo,
Expand Down Expand Up @@ -662,23 +663,7 @@ export function RecordTable_Sequences(
} as CSSProperties
}
>
{warningText && (
<div
style={{
display: 'flex',
flexWrap: 'wrap',
borderLeft: '.2em solid rgb(225, 133, 133)',
borderRight: '.2em solid rgb(225, 133, 133)',
padding: '.5em 1em',
background: 'rgb(255, 228, 228)',
gap: '1em',
marginBottom: '1em',
fontWeight: 500,
}}
>
{warningText}
</div>
)}
{warningText && <NoteBox type="error">{warningText}</NoteBox>}
Copy link
Member

Choose a reason for hiding this comment

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

we should either change warningText to errorText or use the type='warning'. Having "warning" text in an error Notebox is confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is one of those things where someone wanted the box to be red, even though it isn't strictly an error. I will change it to errorText for clarity.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

<div
style={{
padding: '10px',
Expand Down
Loading