Skip to content

Commit

Permalink
feat(base html components): renamed the internally used base styled h…
Browse files Browse the repository at this point in the history
…tml elements, and exported them

This helps remove ambiguity as "Button" (the html element) no longer needs to be aliased on import
`import { Button as ButtonElement } from '../htmlElements.ts';` and it's all in all less confusing.

fix #388
  • Loading branch information
aVileBroker committed May 13, 2022
1 parent 9f713a6 commit d80004b
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 87 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ In this hello world example, you can see the Card component has preset styling f
```
// /foundry-react-ui/src/components/Card/Card.tsx
export const CardContainer = styled(Div)`
export const CardContainer = styled(StyledBaseDiv)`
${({ elevation }: { elevation: number }) => {
const { grayXlight, background, shadow } = useColors();
return `
Expand All @@ -106,7 +106,7 @@ export const CardContainer = styled(Div)`
...
export const Body = styled(Div)`
export const Body = styled(StyledBaseDiv)`
${() => {
const { grayMedium } = useColors();
return `
Expand Down Expand Up @@ -235,8 +235,8 @@ const MyContainer = styled.div`styles`;

// do this
import styled from 'styled-components';
import { Div } from 'path/to/htmlElements';
const MyContainer = styled(Div)`styles here`;
import { StyledBaseDiv } from 'path/to/htmlElements';
const MyContainer = styled(StyledBaseDiv)`styles here`;
```

### Passing Refs to Children Elements
Expand Down
4 changes: 2 additions & 2 deletions src/components/Appendix/Appendix.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import styled from 'styled-components';

import { Story, Meta } from '@storybook/react';

import { Div } from '../../htmlElements';
import { StyledBaseDiv } from '../../htmlElements';

const DocContainer = styled(Div)`
const DocContainer = styled(StyledBaseDiv)`
justify-self: flex-start;
padding: 2rem;
max-width: 60rem;
Expand Down
6 changes: 3 additions & 3 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useAnalytics, useTheme } from '../../context';
import variants from '../../enums/variants';
import Skeleton from '../Skeleton/Skeleton';
import Progress from '../Progress/Progress';
import { Div, Button as ButtonElement } from '../../htmlElements';
import { StyledBaseDiv, StyledBaseButton } from '../../htmlElements';
import {
getFontColorFromVariant,
getBackgroundColorFromVariant,
Expand Down Expand Up @@ -140,7 +140,7 @@ export const ButtonContainer: string & StyledComponentBase<any, {}, ButtonContai
}}
`;

const IconContainer = styled(Div)`
const IconContainer = styled(StyledBaseDiv)`
vertical-align: middle;
`;

Expand Down Expand Up @@ -213,7 +213,7 @@ const Button = ({

// get everything we expose + anything consumer wants to send to container
const mergedContainerProps = {
as: ButtonElement,
a: StyledBaseButton,
id,
isLoading,
onClick: (e: any) => handleEventWithAnalytics('Button', onClick, 'onClick', e, containerProps),
Expand Down
10 changes: 5 additions & 5 deletions src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components';
import { darken } from 'polished';

import timings from '../../enums/timings';
import { Div } from '../../htmlElements';
import { StyledBaseDiv } from '../../htmlElements';
import { SubcomponentPropsType, StyledSubcomponentType } from '../commonTypes';
import { useAnalytics, useTheme } from '../../context';
import { getShadowStyle } from '../../utils/styles';
Expand All @@ -20,7 +20,7 @@ export type CardContainerProps = {
isDefaultOnClick: boolean;
};

export const CardContainer = styled(Div)`
export const CardContainer = styled(StyledBaseDiv)`
${({ elevation, feedbackType, isDefaultOnClick }: CardContainerProps) => {
const { colors } = useTheme();
Expand Down Expand Up @@ -55,7 +55,7 @@ export const CardContainer = styled(Div)`
}}
`;

export const Header = styled(Div)`
export const Header = styled(StyledBaseDiv)`
${({ hasBody, hasFooter }) => {
const { colors } = useTheme();
Expand All @@ -72,7 +72,7 @@ export const NoPaddingHeader = styled(Header)`
padding: 0;
`;

export const Body = styled(Div)`
export const Body = styled(StyledBaseDiv)`
${() => {
const { colors } = useTheme();
Expand All @@ -83,7 +83,7 @@ export const Body = styled(Div)`
}}
`;

export const Footer = styled(Div)`
export const Footer = styled(StyledBaseDiv)`
${() => {
const { colors } = useTheme();
Expand Down
8 changes: 4 additions & 4 deletions src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { mdiCheck, mdiCheckboxBlank, mdiClose, mdiMinus } from '@mdi/js';
import { darken } from 'polished';
import { useCheckbox } from 'react-aria';
import { useToggleState } from '@react-stately/toggle';
import { Div, Input as InputElement, Label as LabelElement } from '../../htmlElements';
import { StyledBaseDiv, StyledBaseInput, StyledBaseLabel } from '../../htmlElements';
import { SubcomponentPropsType, StyledSubcomponentType } from '../commonTypes';
import { useAnalytics, useTheme } from '../../context';
import variants from '../../enums/variants';
Expand All @@ -16,7 +16,7 @@ import { mergeRefs } from '../../utils/refs';

// Hide checkbox visually but remain accessible to screen readers.
// Source: https://polished.js.org/docs/#hidevisually
export const Input = styled(InputElement).attrs({ type: 'checkbox' })`
export const Input = styled(StyledBaseInput).attrs({ type: 'checkbox' })`
border: 0;
clip: rect(0 0 0 0);
clippath: inset(50%);
Expand All @@ -29,7 +29,7 @@ export const Input = styled(InputElement).attrs({ type: 'checkbox' })`
width: 1px;
`;

export const Label = styled(LabelElement)`
export const Label = styled(StyledBaseLabel)`
${({ disabled }) => {
return `
display: flex;
Expand All @@ -43,7 +43,7 @@ export const Label = styled(LabelElement)`
}}
`;

export const Box = styled(Div)`
export const Box = styled(StyledBaseDiv)`
${({ variant, checked, checkboxType }) => {
const { colors } = useTheme();
let color = colors.grayLight;
Expand Down
6 changes: 3 additions & 3 deletions src/components/Divider/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from 'react';
import styled from 'styled-components';

import { useSeparator } from 'react-aria';
import { Div, HR } from '../../htmlElements';
import { StyledBaseDiv, StyledBaseHR } from '../../htmlElements';
import { SubcomponentPropsType, StyledSubcomponentType } from '../commonTypes';
import { useTheme } from '../../context';

export const DefaultDivider = styled(HR)`
export const DefaultDivider = styled(StyledBaseHR)`
${({ width = '90%', height = '1px' }: { width: string; height: string }) => {
const { colors } = useTheme();
return `
Expand All @@ -18,7 +18,7 @@ export const DefaultDivider = styled(HR)`
}}
`;

export const DefaultDividerContainer = styled(Div)`
export const DefaultDividerContainer = styled(StyledBaseDiv)`
display: flex;
justify-content: center;
margin-top: 10px;
Expand Down
26 changes: 13 additions & 13 deletions src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useAnalytics, useTheme } from '../../context';
import Button from '../Button/Button';
import variants from '../../enums/variants';
import timings from '../../enums/timings';
import { Div, Span, Input } from '../../htmlElements';
import { StyledBaseDiv, StyledBaseSpan, StyledBaseInput } from '../../htmlElements';
import Tag, { TagProps } from '../Tag/Tag';
import { getFontColorFromVariant, getBackgroundColorFromVariant } from '../../utils/color';
import { SubcomponentPropsType, StyledSubcomponentType } from '../commonTypes';
Expand All @@ -33,7 +33,7 @@ type UsefulDropdownState = {
isHidden?: boolean;
};

const Container = styled(Div)`
const Container = styled(StyledBaseDiv)`
${({ elevation, isOpen }) => {
const { colors } = useTheme();
return `
Expand Down Expand Up @@ -75,23 +75,23 @@ export const ValueContainer = styled(Button.Container)`
`;

// TODO: Don't use explicit height here - this div is ending up larger than the icon otherwise
export const CloseIconContainer = styled(Div)`
export const CloseIconContainer = styled(StyledBaseDiv)`
height: 1.125em;
z-index: 1;
`;

export const ArrowIconContainer = styled(Div)`
export const ArrowIconContainer = styled(StyledBaseDiv)`
height: 1.125em;
z-index: 1;
pointer-events: none;
`;

const ValueItem = styled(Div)`
const ValueItem = styled(StyledBaseDiv)`
width: 100%;
text-align: left;
`;

const OptionsContainer = styled(Div)`
const OptionsContainer = styled(StyledBaseDiv)`
${({
color,
variant,
Expand Down Expand Up @@ -136,7 +136,7 @@ const HiddenOptionsContainer = styled(OptionsContainer)`
}}
`;

const OptionItem = styled(Div)`
const OptionItem = styled(StyledBaseDiv)`
${({ selected, color, variant }: UsefulDropdownState) => {
const { colors } = useTheme();
const unselectedBgColor = getBackgroundColorFromVariant(variant, color);
Expand Down Expand Up @@ -170,7 +170,7 @@ const OptionItem = styled(Div)`
}}
`;

const CheckContainer = styled(Div)`
const CheckContainer = styled(StyledBaseDiv)`
${({ color }: UsefulDropdownState) => {
const { colors } = useTheme();
const backgroundColor = getLuminance(color) > 0.5 ? shade(0.125, color) : tint(0.5, color);
Expand All @@ -185,7 +185,7 @@ const CheckContainer = styled(Div)`
}}
`;

const PlaceholderContainer = styled(Div)`
const PlaceholderContainer = styled(StyledBaseDiv)`
position: absolute;
opacity: 0.8;
`;
Expand Down Expand Up @@ -215,9 +215,9 @@ const ValueItemTagContainer = styled(Tag.Container)`
`}
`;

const StyledSearchContainer = styled(Div)``;
const StyledSearchContainer = styled(StyledBaseDiv)``;

const StyledSearchInput = styled(Input)`
const StyledSearchInput = styled(StyledBaseInput)`
all: inherit;
`;

Expand Down Expand Up @@ -949,7 +949,7 @@ const Dropdown = ({
{optionsHash[option.id].isSelected && <Icon path={mdiCheck} size="1em" />}
</StyledCheckContainer>
)}
<Span>{option.optionValue}</Span>
<StyledBaseSpan>{option.optionValue}</StyledBaseSpan>
</StyledOptionItem>
)}
/>
Expand Down Expand Up @@ -981,7 +981,7 @@ const Dropdown = ({
{optionsHash[option.id].isSelected && <Icon path={mdiCheck} size="1em" />}
</StyledCheckContainer>
)}
<Span>{option.optionValue}</Span>
<StyledBaseSpan>{option.optionValue}</StyledBaseSpan>
</StyledOptionItem>
))}
</InternalOptionsContainer>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import styled from 'styled-components';
import Icon from '@mdi/react';
import { mdiCheckBold, mdiAsterisk } from '@mdi/js';
import { useLabel } from 'react-aria';
import { Div, Label as LabelElement, Span } from '../../htmlElements';
import { StyledBaseDiv, StyledBaseLabel, StyledBaseSpan } from '../../htmlElements';
import { SubcomponentPropsType, StyledSubcomponentType } from '../commonTypes';
import { useTheme } from '../../context';

export const DefaultStyledLabel = styled(LabelElement)`
export const DefaultStyledLabel = styled(StyledBaseLabel)`
${({ color }: { color: string }) => {
const { colors } = useTheme();
const labelColor = color || colors.grayLight;
Expand All @@ -20,11 +20,11 @@ export const DefaultStyledLabel = styled(LabelElement)`
}}
`;

export const DefaultStyledTextContainer = styled(Div)``;
export const DefaultStyledTextContainer = styled(StyledBaseDiv)``;

export const DefaultStyledLabelContainer = styled(Div)``;
export const DefaultStyledLabelContainer = styled(StyledBaseDiv)``;

const DefaultStyledIconContainer = styled(Span)`
const DefaultStyledIconContainer = styled(StyledBaseSpan)`
display: inline-flex;
margin-left: 0.25em;
`;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Progress/Progress.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled, { keyframes, css } from 'styled-components';
import { Div } from '../../htmlElements';
import { StyledBaseDiv } from '../../htmlElements';

/* Keyframes for the loading bar gradient */
export const movingGradient = keyframes`
Expand All @@ -14,7 +14,7 @@ export const animation = css`

/* Styled div that represents the scroll bar
Note: The border-radius 9999px is used to create a pill shape */
const Progress = styled(Div)`
const Progress = styled(StyledBaseDiv)`
${() => css`
background: linear-gradient(
45deg,
Expand Down
6 changes: 3 additions & 3 deletions src/components/RangeSlider/RangeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
DomainLabelProps,
} from './types';
import { useAnalytics, useTheme } from '../../context';
import { Div } from '../../htmlElements';
import { StyledBaseDiv } from '../../htmlElements';

export const Container = styled.div`
${({ showDomainLabels, hasHandleLabels, disabled, beingDragged = false }: ContainerProps) => `
Expand Down Expand Up @@ -162,7 +162,7 @@ export const DomainLabel = styled.div`
}}
`;

export const Marker = styled(Div)`
export const Marker = styled(StyledBaseDiv)`
${({ sliderPosition = 0 }) => {
const { colors } = useTheme();
return `
Expand All @@ -177,7 +177,7 @@ export const Marker = styled(Div)`
`;
}}
`;
export const MarkerLabel = styled(Div)`
export const MarkerLabel = styled(StyledBaseDiv)`
${({ color }) => {
const { colors } = useTheme();
return `
Expand Down
6 changes: 3 additions & 3 deletions src/components/Skeleton/Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styled, { keyframes, css } from 'styled-components';

import { useTheme } from '../../context';
import { SubcomponentPropsType, StyledSubcomponentType } from '../commonTypes';
import { Div } from '../../htmlElements';
import { StyledBaseDiv } from '../../htmlElements';

export const movingGradient = keyframes`
0% { background-position: 0vw bottom; }
Expand All @@ -15,7 +15,7 @@ export const animation = css`
${movingGradient} 2s linear infinite;
`;

const SkeletonShimmer = styled(Div)`
const SkeletonShimmer = styled(StyledBaseDiv)`
${({ isLoading, color }) => {
const rgb = parseToRgb(color);
Expand Down Expand Up @@ -48,7 +48,7 @@ const SkeletonShimmer = styled(Div)`
}}
`;

const SkeletonContainer = styled(Div)`
const SkeletonContainer = styled(StyledBaseDiv)`
${({ isLoading }: { isLoading: boolean }) => `
display: block;
Expand Down
Loading

0 comments on commit d80004b

Please sign in to comment.