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

Bump version to 0.48.15, add CONTROL_ICON_OPACITY constant, and update component styles for improved visual consistency #416

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qoretechnologies/reqore",
"version": "0.48.14",
"version": "0.48.15",
"description": "ReQore is a highly theme-able and modular UI library for React",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
8 changes: 7 additions & 1 deletion src/components/Breadcrumbs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, { useMemo } from 'react';
import { useMeasure } from 'react-use';
import styled, { css } from 'styled-components';
import { ReqoreDropdown } from '../..';
import { CONTROL_ICON_OPACITY } from '../../constants/colors';
import { ICON_FROM_SIZE, MARGIN_FROM_SIZE, PADDING_FROM_SIZE, TSizes } from '../../constants/sizes';
import { IReqoreBreadcrumbsTheme, IReqoreTheme, TReqoreIntent } from '../../constants/theme';
import { changeLightness, getReadableColor, getReadableColorFrom } from '../../helpers/colors';
Expand Down Expand Up @@ -188,7 +189,12 @@ const ReqoreBreadcrumbs: React.FC<IReqoreBreadcrumbsProps> = ({
badge={count(itemOrItems)}
items={itemOrItems as IReqoreDropdownItem[]}
>
<ReqoreIcon icon='MoreLine' />
<ReqoreIcon
icon='MoreLine'
effect={{
opacity: CONTROL_ICON_OPACITY,
}}
/>
</ReqoreDropdown>
</React.Fragment>
);
Expand Down
189 changes: 103 additions & 86 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ import { size } from 'lodash';
import { rgba, saturate, tint } from 'polished';
import React, { forwardRef, memo, useCallback, useMemo, useState } from 'react';
import styled, { css } from 'styled-components';
import { CONTROL_ICON_OPACITY } from '../../constants/colors';
import {
CONTROL_HORIZONTAL_PADDING_FROM_SIZE,
CONTROL_TEXT_FROM_SIZE,
CONTROL_VERTICAL_PADDING_FROM_SIZE,
CONTROL_VERTICAL_PADDING_MODIFIER_FROM_SIZE,
ICON_FROM_SIZE,
PADDING_FROM_SIZE,
PILL_RADIUS_MODIFIER,
Expand Down Expand Up @@ -150,22 +154,28 @@ export const StyledButton = styled(StyledEffect)<IReqoreButtonStyle>`
vertical-align: middle;
border: ${({ theme, color, flat, effect }) =>
!flat ? `1px solid ${changeLightness(getButtonMainColor(theme, color, effect), 0.05)}` : 0};
padding: ${({ size, compact, verticalPadding }) =>
`${verticalPadding ? PADDING_FROM_SIZE[verticalPadding] : PADDING_FROM_SIZE[size]}px ${
compact ? PADDING_FROM_SIZE[size] / 2 : PADDING_FROM_SIZE[size]
padding: ${({ size, compact, verticalPadding = 'normal' }) =>
`${
CONTROL_VERTICAL_PADDING_FROM_SIZE[size] +
CONTROL_VERTICAL_PADDING_MODIFIER_FROM_SIZE[verticalPadding]
}px ${
compact
? CONTROL_VERTICAL_PADDING_FROM_SIZE[size]
: CONTROL_HORIZONTAL_PADDING_FROM_SIZE[size]
}px`};
font-size: ${({ size }) => CONTROL_TEXT_FROM_SIZE[size]}px;
outline-offset: -2px;

min-height: ${({ size }) => SIZE_TO_PX[size]}px;
min-height: ${({ size, verticalPadding = 'normal' }) =>
SIZE_TO_PX[size] + CONTROL_VERTICAL_PADDING_MODIFIER_FROM_SIZE[verticalPadding] * 2}px;
min-width: ${({ size }) => SIZE_TO_PX[size]}px;
max-width: ${({ maxWidth, fluid, fixed }) => maxWidth || (fluid && !fixed ? '100%' : undefined)};

${({ wrap, description }) =>
!wrap && !description
? css`
max-height: ${({ size, verticalPadding }) =>
SIZE_TO_PX[size] + (verticalPadding ? PADDING_FROM_SIZE[verticalPadding] * 2 : 0)}px;
max-height: ${({ size, verticalPadding = 'normal' }) =>
SIZE_TO_PX[size] + CONTROL_VERTICAL_PADDING_MODIFIER_FROM_SIZE[verticalPadding] * 2}px;
`
: null}

Expand Down Expand Up @@ -234,7 +244,7 @@ export const StyledButton = styled(StyledEffect)<IReqoreButtonStyle>`
background-color: ${({ theme, color, minimal, transparent }: IReqoreButtonStyle) =>
minimal || transparent
? rgba(
changeLightness(getButtonMainColor(theme, color, effect), 0.05),
changeLightness(getButtonMainColor(theme, color, effect), 0.1),
transparent ? 0.2 : 0.4
)
: changeLightness(getButtonMainColor(theme, color), 0.05)};
Expand Down Expand Up @@ -338,78 +348,81 @@ export interface IReqoreButtonBadgeProps extends IWithReqoreSize {
wrap?: boolean;
wrapGroup?: boolean;
compact?: boolean;
active?: boolean;
}

export const ButtonBadge = memo(({ wrapGroup, compact, ...props }: IReqoreButtonBadgeProps) => {
const renderTag = useCallback(
({ size, color, theme, content, key }: IReqoreButtonBadgeProps & { key: number }) => (
<ReqoreTag
key={key}
size={getOneLessSize(size)}
asBadge
color={color}
customTheme={theme}
className='reqore-button-badge'
labelAlign='center'
minimal={!(content as IReqoreTagProps)?.effect?.gradient}
{...(typeof content === 'string' || typeof content === 'number'
? { label: content }
: (content as IReqoreTagProps))}
/>
),
[props]
);

const content = Array.isArray(props.content) ? props.content : [props.content];

const leftBadges = content.filter(
(badge) => typeof badge === 'string' || typeof badge === 'number' || !badge?.align
);
const rightBadges = content.filter(
(badge) => typeof badge !== 'string' && typeof badge !== 'number' && badge?.align === 'right'
);
const middleBadges = content.filter(
(badge) => typeof badge !== 'string' && typeof badge !== 'number' && badge?.align === 'center'
);

const buildContent = (badge: TReqoreBadge) => {
if (typeof badge === 'string' || typeof badge === 'number') {
return { label: badge, align: undefined };
}

return { ...badge, align: undefined };
};

return (
<>
<ReqoreSpacer
width={props.wrap ? undefined : PADDING_FROM_SIZE[props.size] / (compact ? 2 : 1)}
height={!props.wrap ? undefined : PADDING_FROM_SIZE[props.size] / 2}
/>
{size(leftBadges) ? (
<ReqoreTagGroup wrap={wrapGroup} align='left'>
{leftBadges.map((badge, index) =>
renderTag({ ...props, content: buildContent(badge), key: index })
)}
</ReqoreTagGroup>
) : null}
{size(middleBadges) ? (
<ReqoreTagGroup wrap={wrapGroup} fluid align='center'>
{middleBadges.map((badge, index) =>
renderTag({ ...props, content: buildContent(badge), key: index })
)}
</ReqoreTagGroup>
) : null}
{size(rightBadges) ? (
<ReqoreTagGroup wrap={wrapGroup} align='right'>
{rightBadges.map((badge, index) =>
renderTag({ ...props, content: buildContent(badge), key: index })
)}
</ReqoreTagGroup>
) : null}
</>
);
});
export const ButtonBadge = memo(
({ wrapGroup, compact, active, ...props }: IReqoreButtonBadgeProps) => {
const renderTag = useCallback(
({ size, color, theme, content, key }: IReqoreButtonBadgeProps & { key: number }) => (
<ReqoreTag
key={key}
size={getOneLessSize(size)}
asBadge
color={color}
customTheme={theme}
className='reqore-button-badge'
labelAlign='center'
minimal={!active && !(content as IReqoreTagProps)?.effect?.gradient}
{...(typeof content === 'string' || typeof content === 'number'
? { label: content }
: (content as IReqoreTagProps))}
/>
),
[props]
);

const content = Array.isArray(props.content) ? props.content : [props.content];

const leftBadges = content.filter(
(badge) => typeof badge === 'string' || typeof badge === 'number' || !badge?.align
);
const rightBadges = content.filter(
(badge) => typeof badge !== 'string' && typeof badge !== 'number' && badge?.align === 'right'
);
const middleBadges = content.filter(
(badge) => typeof badge !== 'string' && typeof badge !== 'number' && badge?.align === 'center'
);

const buildContent = (badge: TReqoreBadge) => {
if (typeof badge === 'string' || typeof badge === 'number') {
return { label: badge, align: undefined };
}

return { ...badge, align: undefined };
};

return (
<>
<ReqoreSpacer
width={props.wrap ? undefined : PADDING_FROM_SIZE[props.size] / (compact ? 2 : 1)}
height={!props.wrap ? undefined : PADDING_FROM_SIZE[props.size] / 2}
/>
{size(leftBadges) ? (
<ReqoreTagGroup wrap={wrapGroup} align='left'>
{leftBadges.map((badge, index) =>
renderTag({ ...props, content: buildContent(badge), key: index })
)}
</ReqoreTagGroup>
) : null}
{size(middleBadges) ? (
<ReqoreTagGroup wrap={wrapGroup} fluid align='center'>
{middleBadges.map((badge, index) =>
renderTag({ ...props, content: buildContent(badge), key: index })
)}
</ReqoreTagGroup>
) : null}
{size(rightBadges) ? (
<ReqoreTagGroup wrap={wrapGroup} align='right'>
{rightBadges.map((badge, index) =>
renderTag({ ...props, content: buildContent(badge), key: index })
)}
</ReqoreTagGroup>
) : null}
</>
);
}
);

const ReqoreButton = memo(
forwardRef<HTMLButtonElement, IReqoreButtonProps>(
Expand Down Expand Up @@ -466,14 +479,15 @@ const ReqoreButton = memo(
// If color or intent was specified, set the color
const customColor = intent ? theme.main : changeLightness(theme.main, 0.07);
const _flat = minimal ? flat : flat === true;
const _compact = compact ?? theme.buttons?.compact;

const color: TReqoreHexColor = customColor
? minimal
? getReadableColor(theme, undefined, undefined, true, theme.originalMain)
: getReadableColorFrom(customColor, true)
: getReadableColor(theme, undefined, undefined, true);

const _children = useMemo(() => label || children, [label, children]);
const _compact = compact ?? theme.buttons?.compact ?? !children;
const hasLeftIcon = icon || leftIconProps?.image;
const hasRightIcon = rightIcon || rightIconProps?.image;

Expand Down Expand Up @@ -531,7 +545,10 @@ const ReqoreButton = memo(
<ReqoreIcon
size={size}
color={leftIconColor || iconColor}
compact={_compact}
compact
effect={{
opacity: CONTROL_ICON_OPACITY,
}}
{...leftIconProps}
style={
textAlign !== 'left' || iconsAlign === 'center' || !_children
Expand All @@ -550,7 +567,7 @@ const ReqoreButton = memo(
icon={leftIcon}
/>
{_children || hasRightIcon ? (
<ReqoreSpacer width={PADDING_FROM_SIZE[size] / (_compact ? 2 : 1)} />
<ReqoreSpacer width={PADDING_FROM_SIZE[size] / 2} />
) : null}
</>
) : _children ? (
Expand Down Expand Up @@ -603,18 +620,18 @@ const ReqoreButton = memo(
</StyledInvisibleContent>
)}
{(badge || badge === 0) && wrap ? (
<ButtonBadge content={badge} size={size} theme={theme} wrap />
<ButtonBadge content={badge} size={size} wrap active={active} />
) : null}
</StyledAnimatedTextWrapper>
)}
{(badge || badge === 0) && !wrap ? (
<ButtonBadge
content={badge}
size={size}
theme={theme}
compact={_compact}
wrapGroup={false}
wrap={false}
active={active}
/>
) : null}
{!hasRightIcon ? (
Expand All @@ -630,14 +647,14 @@ const ReqoreButton = memo(
) : null
) : (
<>
{_children || badge ? (
<ReqoreSpacer width={PADDING_FROM_SIZE[size] / (_compact ? 2 : 1)} />
) : null}
{_children || badge ? <ReqoreSpacer width={PADDING_FROM_SIZE[size] / 2} /> : null}
<ReqoreIcon
icon={rightIcon}
size={size}
color={rightIconColor || iconColor}
compact={_compact}
effect={{
opacity: CONTROL_ICON_OPACITY,
}}
{...rightIconProps}
style={
textAlign !== 'right' || iconsAlign === 'center'
Expand Down
14 changes: 7 additions & 7 deletions src/components/Checkbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import styled, { css } from 'styled-components';
import {
CONTROL_TEXT_FROM_SIZE,
PADDING_FROM_SIZE,
SIZE_TO_PX,
TAG_SIZE_TO_PX,
TSizes,
} from '../../constants/sizes';
import { IReqoreTheme } from '../../constants/theme';
Expand Down Expand Up @@ -72,12 +72,12 @@ const StyledSwitchToggle = styled.div`
align-items: center;
justify-content: center;
position: absolute;
height: ${({ size }) => SIZE_TO_PX[size] - 4}px;
width: ${({ size, width }) => width || SIZE_TO_PX[size] - 4}px;
height: ${({ size }) => TAG_SIZE_TO_PX[size] - 4}px;
width: ${({ size, width }) => width || TAG_SIZE_TO_PX[size] - 4}px;
top: 50%;
transform: translateY(-50%);
left: ${({ checked, size, width }) =>
!checked ? '1px' : `calc(100% - ${width || SIZE_TO_PX[size] - 4}px - 1px)`};
!checked ? '1px' : `calc(100% - ${width || TAG_SIZE_TO_PX[size] - 4}px - 1px)`};
border-radius: 50px;
background-color: ${({ theme, checked, transparent, parentEffect }) =>
transparent
Expand All @@ -99,8 +99,8 @@ const StyledSwitch = styled(StyledEffect)<IReqoreCheckboxStyle>`
justify-content: center;
flex-shrink: 0;

height: ${({ size }) => SIZE_TO_PX[size]}px;
min-width: ${({ size }) => SIZE_TO_PX[size] * 1.8}px;
height: ${({ size }) => TAG_SIZE_TO_PX[size]}px;
min-width: ${({ size }) => TAG_SIZE_TO_PX[size] * 1.8}px;

border: 1px solid ${({ theme, checked }) => changeLightness(theme.main, checked ? 0.35 : 0.2)};
border-radius: 50px;
Expand Down Expand Up @@ -145,7 +145,7 @@ const StyledCheckbox = styled.div<IReqoreCheckboxStyle>`
padding: 0px;
transition: all 0.2s ease-out;

height: ${({ size }) => SIZE_TO_PX[size]}px;
height: ${({ size }) => TAG_SIZE_TO_PX[size]}px;
font-size: ${({ size }) => CONTROL_TEXT_FROM_SIZE[size]}px;

max-width: ${({ fluid, fixed }) => (fluid && !fixed ? '100%' : undefined)};
Expand Down
10 changes: 9 additions & 1 deletion src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { omit } from 'lodash';
import { rgba } from 'polished';
import React, { forwardRef, useState } from 'react';
import styled, { css } from 'styled-components';
import { CONTROL_ICON_OPACITY } from '../../constants/colors';
import {
CONTROL_TEXT_FROM_SIZE,
PADDING_FROM_SIZE,
Expand Down Expand Up @@ -257,6 +258,7 @@ const ReqoreInput = forwardRef<HTMLDivElement, IReqoreInputProps>(
<ReqoreIcon
size={size}
color={iconColor}
effect={{ opacity: CONTROL_ICON_OPACITY }}
{...leftIconProps}
icon={leftIcon}
animation={loading ? 'spin' : leftIconProps?.animation}
Expand Down Expand Up @@ -303,7 +305,13 @@ const ReqoreInput = forwardRef<HTMLDivElement, IReqoreInputProps>(
/>
{hasRightIcon && (
<StyledIconWrapper _size={size} position='right'>
<ReqoreIcon size={size} icon={rightIcon} color={rightIconColor} {...rightIconProps} />
<ReqoreIcon
size={size}
icon={rightIcon}
color={rightIconColor}
effect={{ opacity: CONTROL_ICON_OPACITY }}
{...rightIconProps}
/>
</StyledIconWrapper>
)}
</StyledInputWrapper>
Expand Down
Loading
Loading