Skip to content

Commit

Permalink
fix: html base pixel unit: changes the base from 16 to 10 (EightfoldA…
Browse files Browse the repository at this point in the history
…I#34)

Match the pixel base of vscode
  • Loading branch information
dkilgore-eightfold authored Apr 4, 2022
1 parent d9d104e commit 8febb95
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 163 deletions.
2 changes: 1 addition & 1 deletion src/components/Button/BaseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const BaseButton: FC<InternalButtonProps> = ({
>
{iconExists && !textExists && getButtonIcon(icon)}
{iconExists && textExists && (
<span className={styles.flexStructureHorizontal}>
<span>
{getButtonIcon(icon)}
{getButtonText(buttonTextClassNames, text)}
</span>
Expand Down
7 changes: 6 additions & 1 deletion src/components/Button/button.module.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
.button {
background-color: inherit;
border: rem(2px) solid $button-color-default-active;
border-radius: $corner-radius-s;
cursor: pointer;
display: inline-block;
transition: all $motion-duration-extra-fast $motion-easing-easeinout 0s;
white-space: nowrap;

border-radius: $corner-radius-s;
span {
display: flex;
flex-direction: row;
align-items: center;
}

.icon + .button1:not(:empty) {
margin-left: $button-spacer-large;
Expand Down
9 changes: 5 additions & 4 deletions src/components/ConfigProvider/ConfigProvider.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const ThemedComponents = () => {

return (
<>
<h2>
<h1>
Selected Theme:
<span
style={{
Expand All @@ -55,17 +55,18 @@ const ThemedComponents = () => {
>
{themeOptions.name}
</span>
</h2>
</h1>
<div style={{ display: 'flex', alignItems: 'flex-start' }}>
<div style={{ marginRight: '40px' }}>
<h3>Predefined</h3>
<h2>Predefined</h2>
<select
value={themeOptions.name}
onChange={(e) => {
setThemeOptions({
name: e.target.value as OcThemeNames,
});
}}
style={{ fontSize: '1.4rem' }}
>
{themes.map((theme) => (
<option value={theme} key={theme}>
Expand All @@ -76,7 +77,7 @@ const ThemedComponents = () => {
</div>
<br />
<div>
<h3>Custom</h3>
<h2>Custom</h2>
<CompactPicker
color={customColor}
onChange={(color) => {
Expand Down
16 changes: 11 additions & 5 deletions src/components/Icon/Icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ export default {

export const Icons = () => (
<>
<h2>Icons</h2>
<p>X-Small</p>
<h1>Icons</h1>
<h2>X-Small</h2>
<Icon path={IconName.mdiCardsHeart} size={IconSize.XSmall} />
<p>Small</p>
<br />
<br />
<h2>Small</h2>
<Icon path={IconName.mdiCardsHeart} size={IconSize.Small} />
<p>Medium</p>
<br />
<br />
<h2>Medium</h2>
<Icon path={IconName.mdiCardsHeart} />
<p>Large</p>
<br />
<br />
<h2>Large</h2>
<Icon path={IconName.mdiCardsHeart} size={IconSize.Large} />
</>
);
8 changes: 4 additions & 4 deletions src/components/Icon/Icon.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { IconName } from './mdi';
import { IconProps as MdiIconProps } from '@mdi/react/dist/IconProps';

export enum IconSize {
Large = '1.5rem',
Medium = '1.25rem',
Small = '1rem',
XSmall = '0.875rem',
Large = '2.4rem',
Medium = '2rem',
Small = '1.6rem',
XSmall = '1.4rem',
}

export interface IconProps extends MdiIconProps {
Expand Down
24 changes: 20 additions & 4 deletions src/components/Pills/Pill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ export const Pill: FC<PillProps> = ({
type = PillType.default,
size = PillSize.Large,
}) => {
const pillSizeToButtonSizeMap = new Map<PillSize, ButtonSize>([
[PillSize.Large, ButtonSize.Medium],
[PillSize.Medium, ButtonSize.Small],
[PillSize.Small, ButtonSize.Small],
]);
const pillSizeToIconSizeMap = new Map<PillSize, IconSize>([
[PillSize.Large, IconSize.Medium],
[PillSize.Medium, IconSize.Small],
[PillSize.Small, IconSize.XSmall],
]);
const labelClassName: string = classNames([
styles.label,
{ [styles.header4]: size === PillSize.Large },
{ [styles.header5]: size === PillSize.Medium },
{ [styles.header6]: size === PillSize.Small },
]);
const tagClassName: string = classNames([
styles.tagPills,
{ [styles.red]: theme === 'red' },
Expand All @@ -36,16 +52,16 @@ export const Pill: FC<PillProps> = ({
{icon && (
<Icon
path={icon}
size={IconSize.Small}
size={pillSizeToIconSizeMap.get(size)}
className={styles.icon}
/>
)}
<span className={styles.label}>{label}</span>
<span className={labelClassName}>{label}</span>
{type === PillType.withButton && (
<DefaultButton
{...pillButtonProps}
onClick={onClick}
size={ButtonSize.Small}
size={pillSizeToButtonSizeMap.get(size)}
className={styles.button}
/>
)}
Expand All @@ -54,7 +70,7 @@ export const Pill: FC<PillProps> = ({
{...closeButtonProps}
icon={IconName.mdiClose}
onClick={onClose}
size={ButtonSize.Small}
size={pillSizeToButtonSizeMap.get(size)}
className={styles.closeButton}
/>
)}
Expand Down
27 changes: 8 additions & 19 deletions src/components/Pills/pills.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,8 @@
align-items: center;

.label {
font-weight: $text-font-weight-semibold;
font-size: $text-font-size-5;
}

&.medium {
.label {
font-size: $text-font-size-3;
}
}

&.small {
.label {
font-size: $text-font-size-2;
}
}

&:hover {
--bg: var(--hover-bg);
--label: var(--hover-label);
margin-bottom: rem(1px);
margin-top: rem(-1px);
}

&.red {
Expand Down Expand Up @@ -86,6 +69,11 @@
--hover-bg: var(--grey-color-30);
}

&:hover {
--bg: var(--hover-bg);
--label: var(--hover-label);
}

.button,
.close-button {
border: none;
Expand All @@ -94,6 +82,7 @@
color: inherit;
padding: 0;
margin: 0 0 0 $space-xxs;
transition: none;
}

.label + .button:not(:empty) {
Expand Down
1 change: 1 addition & 0 deletions src/components/Tabs/tabs.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

.label {
font-weight: $text-font-weight-semibold;
font-size: $text-font-size-3;
white-space: nowrap;
}

Expand Down
1 change: 1 addition & 0 deletions src/components/Tooltip/tooltip.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ $tooltip-arrow-shadow: 1px 1px 2px rgba(15, 20, 31, 0.12);
box-shadow: $shadow-object-xs;
background: var(--bg);
color: var(--text-color);
font-size: $text-font-size-1;
text-align: center;
z-index: $z-index-100;
padding: $space-xs;
Expand Down
104 changes: 99 additions & 5 deletions src/styles/abstracts/_functions.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,101 @@
$html-font-size: 16px;
@function stripUnit($value) {
@return calc($value / ($value * 0 + 1px));
// Extend sass-rem https://github.com/pierreburel/sass-rem
// Update $baseline to set base pixel value

@use 'sass:list';
@use 'sass:map';
@use 'sass:math';
@use 'sass:meta';

$baseline: 10px !default;
$fallback: false !default;
$px-only: false !default;

// Dart Sass <1.33.0 compatibility
@function _divide($a, $b) {
@if map.has-key(meta.module-functions('math'), 'div') {
@return math.div($a, $b);
}

@return $a / $b;
}
@function rem($pxValue) {
@return #{calc(stripUnit($pxValue) / stripUnit($html-font-size))}rem;

@function _convert($to, $values...) {
$result: ();
$separator: list.separator($values);

@each $value in $values {
@if meta.type-of($value) ==
'number' and
math.unit($value) ==
'rem' and
$to ==
'px'
{
$result: list.append(
$result,
_divide($value, 1rem) * $baseline,
$separator
);
} @else if
meta.type-of($value) ==
'number' and
math.unit($value) ==
'px' and
$to ==
'rem'
{
$result: list.append(
$result,
_divide($value, $baseline) * 1rem,
$separator
);
} @else if meta.type-of($value) == 'list' {
$result: list.append($result, _convert($to, $value...), $separator);
} @else {
$result: list.append($result, $value, $separator);
}
}

@return if(list.length($result) == 1, list.nth($result, 1), $result);
}

@function convert($values...) {
@if $px-only {
@return _convert(px, $values...);
} @else {
@return _convert(rem, $values...);
}
}

@mixin convert($properties, $values...) {
@if meta.type-of($properties) == 'map' {
@each $property, $values in $properties {
@include convert($property, $values);
}
} @else {
@each $property in $properties {
@if $fallback or $px-only {
#{$property}: _convert(px, $values...);
}
@if not $px-only {
#{$property}: _convert(rem, $values...);
}
}
}
}

@function rem($values...) {
@return convert($values...);
}

@mixin rem($properties, $values...) {
@include convert($properties, $values...);
}

@mixin baseline($zoom: 100%) {
font-size: _divide($zoom, 16px) * $baseline;
}

html {
@include baseline;
}
Loading

0 comments on commit 8febb95

Please sign in to comment.