ghost-portal/packages/react-components/src/Badge.tsx
MiZiet 5b65c111d1
Add new menu styling (#4317)
* POC displaying route in Tabs

* WIP Add new menu style

Co-authored-by: Krzysztof Jelski <krzysztof-jelski@users.noreply.github.com>

* Rename Section to CurrentSection

* Add new Tabs styling

* WIP Add new menu styling

* Set menu's max-width

* Add theme styles to menu

* Change font size and font weight

* Remove r

* Remove console logs

* Update header styles

* Fix settings link padding

* Change nav link font weight

* Change settings link font weight

* Fix settings link paddings

* Change nav links font size

* Add menu padding

* Change badge paddings

* Change counter badge color to grey

* Add space between menu items

* Change chain name font styles

* Remove color setting from chain css class

* Restore previous whitish color

* Move NodeInfo component to .menuContainer

* Restore font-weights

* Increase the max-width of chain name

* Set darker color for TabsSectionDelimiter

* Center vertically the left chain icon

* Change ChainInfo's elements align and font-sizes

* storke highlight

* Restore ChainInfo alignment

* Revert badges colors

* Align right search bar

* Change menu styling to prevent menu lists blending

* Remove scrollbar from tabs

* Resolve problem with search bar placement

* Add margin-bottom to settings tab

* Change setting padding when there is no badge

* Make tab underline to ignore badge and move it under tabs bar

* WIP Change menu

* Apply contrast to menu hover

* Add bright menu hover for chains with dark chain color

* Add chain color to menu list

* Set menu list hover

* Add badge styles

* Align items badge

Co-authored-by: Krzysztof Jelski <krzysztof-jelski@users.noreply.github.com>
Co-authored-by: Krzysztof Jelski <krzysztof@ethworks.io>
Co-authored-by: alexcherman <sashacherman@gmail.com>
Co-authored-by: Jaco Greeff <jacogr@gmail.com>
Co-authored-by: Ewa Kowalska <ewcia.kowalska@gmail.com>
2021-03-24 10:27:37 +01:00

131 lines
2.6 KiB
TypeScript

// Copyright 2017-2021 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { IconName } from '@fortawesome/fontawesome-svg-core';
import React, { useState } from 'react';
import styled from 'styled-components';
import Icon from './Icon';
import Tooltip from './Tooltip';
interface Props {
className?: string;
color: 'blue' | 'gray' | 'green' | 'highlight' | 'normal' | 'orange' | 'purple' | 'red' | 'transparent' | 'white';
hover?: React.ReactNode;
icon?: IconName;
info?: React.ReactNode;
isSmall?: boolean;
onClick?: () => void;
}
let badgeId = 0;
function Badge ({ className = '', color = 'normal', hover, icon, info, isSmall, onClick }: Props): React.ReactElement<Props> | null {
const [trigger] = useState(() => `badge-hover-${Date.now()}-${badgeId++}`);
const extraProps = hover
? { 'data-for': trigger, 'data-tip': true }
: {};
const isHighlight = color === 'highlight';
return (
<div
{...extraProps}
className={`ui--Badge${hover ? ' isTooltip' : ''}${isSmall ? ' isSmall' : ''}${onClick ? ' isClickable' : ''}${isHighlight ? ' highlight--bg' : ''} ${color}Color ${className}`}
onClick={onClick}
>
<div className={isHighlight ? 'highlight--color-contrast' : ''}>{info || (icon && <Icon icon={icon} />)}</div>
{hover && (
<Tooltip
text={hover}
trigger={trigger}
/>
)}
</div>
);
}
export default React.memo(styled(Badge)`
border-radius: 16px;
box-sizing: border-box;
color: #eeedec;
display: inline-block;
font-size: 12px;
height: 22px;
line-height: 22px;
margin-right: 0.25rem;
min-width: 22px;
padding: 0 4px;
overflow: hidden;
text-align: center;
vertical-align: middle;
width: 22px;
&.isTooltip {
cursor: help;
}
.ui--Icon {
cursor: inherit;
margin-top: 5px;
vertical-align: top;
width: 1em;
}
&.isClickable {
cursor: pointer;
}
&.isSmall {
font-size: 10px;
height: 16px;
line-height: 16px;
min-width: 16px;
padding: 0;
width: 16px;
.ui--Icon {
margin-top: 3px;
}
}
&.blueColor {
background: steelblue;
}
&.counterColor {
margin: 0 0.5rem;
vertical-align: middle;
}
&.grayColor {
background: #eeedec !important;
color: #aaa9a8;
}
&.redColor {
background: darkred;
}
&.greenColor {
background: green;
}
&.orangeColor {
background: darkorange;
}
&.purpleColor {
background: indigo;
}
&.transparentColor {
background: transparent;
box-shadow: none;
}
&.whiteColor {
background: rgba(255, 255, 255, 0.3);
}
`);