Skip to content

Commit

Permalink
Improvement on Section Notice (mattermost#28859)
Browse files Browse the repository at this point in the history
* Improvement on Section Notice

* Address feedback
  • Loading branch information
larkox authored Oct 29, 2024
1 parent 7803c10 commit 97c7c25
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';

import {renderWithContext} from 'tests/react_testing_utils';

import SectionNotice from './section_notice';
import SectionNotice from '.';

type Props = ComponentProps<typeof SectionNotice>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import {useIntl} from 'react-intl';

import Markdown from 'components/markdown';

import SectionNoticeButton from './section_notice_button';
import type {SectionNoticeButtonProp} from './types';

import './section_notice.scss';

type Button = {
onClick: () => void;
text: string;
}
type Props = {
title: string | React.ReactElement;
text?: string;
primaryButton?: Button;
secondaryButton?: Button;
linkButton?: Button;
type?: 'info' | 'success' | 'danger' | 'welcome' | 'warning';
primaryButton?: SectionNoticeButtonProp;
secondaryButton?: SectionNoticeButtonProp;
linkButton?: SectionNoticeButtonProp;
type?: 'info' | 'success' | 'danger' | 'welcome' | 'warning' | 'hint';
isDismissable?: boolean;
onDismissClick?: () => void;
};

const iconByType = {
info: 'icon-information-outline',
hint: 'icon-lightbulb-outline',
success: 'icon-check',
danger: 'icon-alert-outline',
warning: 'icon-alert-outline',
Expand All @@ -45,40 +45,34 @@ const SectionNotice = ({
const intl = useIntl();
const icon = iconByType[type];
const showDismiss = Boolean(isDismissable && onDismissClick);
const buttonClass = 'btn btn-sm sectionNoticeButton';
const hasButtons = Boolean(primaryButton || secondaryButton || linkButton);
return (
<div className={classNames('sectionNoticeContainer', type)}>
<div className={'sectionNoticeContent'}>
{icon && <i className={classNames('icon sectionNoticeIcon', icon, type)}/>}
<div className='sectionNoticeBody'>
<h4 className={classNames('sectionNoticeTitle', {welcome: type === 'welcome', noText: !text})}>{title}</h4>
{text && <Markdown message={text}/>}
{(primaryButton || secondaryButton || linkButton) && (
{hasButtons && (
<div className='sectionNoticeActions'>
{primaryButton && (
<button
onClick={primaryButton.onClick}
className={classNames(buttonClass, 'btn-primary')}
>
{primaryButton.text}
</button>
)}
{secondaryButton && (
<button
onClick={secondaryButton.onClick}
className={classNames(buttonClass, 'btn-secondary')}
>
{secondaryButton.text}
</button>
)}
{linkButton && (
<button
onClick={linkButton.onClick}
className={classNames(buttonClass, 'btn-link')}
>
{linkButton.text}
</button>
)}
{primaryButton &&
<SectionNoticeButton
button={primaryButton}
buttonClass='btn-primary'
/>
}
{secondaryButton &&
<SectionNoticeButton
button={secondaryButton}
buttonClass='btn-tertiary'
/>
}
{linkButton &&
<SectionNoticeButton
button={linkButton}
buttonClass='btn-link'
/>
}
</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
margin: 0;
}

&.info {
&.info, &.hint {
border-color: rgba(var(--sidebar-text-active-border-rgb), 0.16);
background: rgba(var(--sidebar-text-active-border-rgb), 0.08);

Expand Down Expand Up @@ -76,7 +76,7 @@
.sectionNoticeIcon {
font-size: 20px;

&.info {
&.info, &.hint {
color: var(--sidebar-text-active-border);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import classNames from 'classnames';
import React from 'react';

import type {SectionNoticeButtonProp} from './types';

type Props = {
button: SectionNoticeButtonProp;
buttonClass: 'btn-primary' | 'btn-tertiary' | 'btn-link';
}

const SectionNoticeButton = ({
button,
buttonClass,
}: Props) => {
const leading = button.leadingIcon ? (<i className={classNames('icon', button.leadingIcon)}/>) : null;
const trailing = button.trailingIcon ? (<i className={classNames('icon', button.trailingIcon)}/>) : null;
return (
<button
onClick={button.onClick}
className={classNames('btn btn-sm sectionNoticeButton', buttonClass)}
>
{button.loading && (<i className='icon fa fa-pulse fa-spinner'/>)}
{leading}
{button.text}
{trailing}
</button>
);
};

export default SectionNoticeButton;
10 changes: 10 additions & 0 deletions webapp/channels/src/components/section_notice/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

export type SectionNoticeButtonProp = {
onClick: () => void;
text: string;
trailingIcon?: string;
leadingIcon?: string;
loading?: boolean;
}

0 comments on commit 97c7c25

Please sign in to comment.