Skip to content

Commit bde588c

Browse files
WesSouzaarturbien
authored andcommitted
refactor(frame): categorize under Layout, rename Panel to Frame
This also adds the field variant and refactors createBorderStyles to implement all border styles.
1 parent 8256a47 commit bde588c

File tree

15 files changed

+286
-182
lines changed

15 files changed

+286
-182
lines changed

src/Button/Button.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
createDisabledTextStyles,
77
createFlatBoxStyles,
88
createHatchedBackground,
9-
createWellBorderStyles,
109
focusOutline
1110
} from '../common';
1211
import { blockSizes } from '../common/system';
@@ -107,12 +106,14 @@ export const StyledButton = styled.button<StyledButtonProps>`
107106
border: 2px solid transparent;
108107
&:hover,
109108
&:focus {
110-
${!disabled && !active && createWellBorderStyles(false)}
109+
${!disabled &&
110+
!active &&
111+
createBorderStyles({ style: 'buttonThin' })}
111112
}
112113
&:active {
113-
${!disabled && createWellBorderStyles(true)}
114+
${!disabled && createBorderStyles({ style: 'buttonThinPressed' })}
114115
}
115-
${active && createWellBorderStyles(true)}
116+
${active && createBorderStyles({ style: 'buttonThinPressed' })}
116117
${disabled && createDisabledTextStyles()}
117118
`
118119
: css`

src/Counter/Counter.stories.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentMeta } from '@storybook/react';
22
import React, { useState } from 'react';
3-
import { Button, Counter, Panel } from 'react95';
3+
import { Button, Counter, Frame } from 'react95';
44
import styled from 'styled-components';
55

66
const Wrapper = styled.div`
@@ -29,14 +29,14 @@ export function Default() {
2929
const [count, setCount] = useState(13);
3030
const handleClick = () => setCount(count + 1);
3131
return (
32-
<Panel className='wrapper'>
32+
<Frame className='wrapper'>
3333
<Counter value={123456789} minLength={11} size='lg' />
3434

3535
<div className='counter-wrapper'>
3636
<Counter value={count} minLength={3} />
3737
<Button onClick={handleClick}>Click!</Button>
3838
</div>
39-
</Panel>
39+
</Frame>
4040
);
4141
}
4242

src/Counter/Counter.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { forwardRef, useMemo } from 'react';
22
import styled from 'styled-components';
33

4-
import { createWellBorderStyles } from '../common';
4+
import { createBorderStyles } from '../common';
55
import { CommonStyledProps, Sizes } from '../types';
66
import { Digit } from './Digit';
77

@@ -13,7 +13,7 @@ type CounterProps = {
1313
CommonStyledProps;
1414

1515
const CounterWrapper = styled.div`
16-
${createWellBorderStyles(true)}
16+
${createBorderStyles({ style: 'status' })}
1717
display: inline-flex;
1818
background: #000000;
1919
`;

src/Frame/Frame.spec.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { render } from '@testing-library/react';
2+
import React from 'react';
3+
4+
import { Frame } from './Frame';
5+
6+
describe('<Frame />', () => {
7+
it('should render frame', () => {
8+
const { container } = render(<Frame />);
9+
const frame = container.firstElementChild;
10+
11+
expect(frame).toBeInTheDocument();
12+
});
13+
14+
it('should render custom styles', () => {
15+
const { container } = render(
16+
<Frame style={{ backgroundColor: 'papayawhip' }} />
17+
);
18+
const frame = container.firstElementChild;
19+
20+
expect(frame).toHaveAttribute('style', 'background-color: papayawhip;');
21+
});
22+
23+
it('should render children', async () => {
24+
const { findByText } = render(
25+
<Frame>
26+
<span>Cool frame</span>
27+
</Frame>
28+
);
29+
const content = await findByText(/cool frame/i);
30+
31+
expect(content).toBeInTheDocument();
32+
});
33+
34+
it('should render custom props', () => {
35+
const customProps = { title: 'frame' };
36+
const { container } = render(<Frame {...customProps} />);
37+
const frame = container.firstElementChild;
38+
39+
expect(frame).toHaveAttribute('title', 'frame');
40+
});
41+
});

src/Panel/Panel.stories.tsx renamed to src/Frame/Frame.stories.tsx

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ComponentMeta } from '@storybook/react';
22
import React from 'react';
3-
import { Panel } from 'react95';
3+
import { Frame } from 'react95';
44
import styled from 'styled-components';
55

66
const Wrapper = styled.div`
@@ -19,46 +19,48 @@ const Wrapper = styled.div`
1919
`;
2020

2121
export default {
22-
title: 'Panel',
23-
component: Panel,
22+
title: 'Layout/Frame',
23+
component: Frame,
2424
decorators: [story => <Wrapper>{story()}</Wrapper>]
25-
} as ComponentMeta<typeof Panel>;
25+
} as ComponentMeta<typeof Frame>;
2626

2727
export function Default() {
2828
return (
29-
<Panel
29+
<Frame
3030
variant='outside'
3131
shadow
3232
style={{ padding: '0.5rem', lineHeight: '1.5', width: 600 }}
3333
>
3434
<p style={{ padding: '0.5rem' }}>
35-
Notice the subtle difference in borders. The lightest border is not on
36-
the edge of this panel.
35+
This is a frame of the &apos;window&apos; variant, the default. Notice
36+
the subtle difference in borders. The lightest border is not on the edge
37+
of this frame.
3738
</p>
38-
<Panel variant='inside' style={{ margin: '1rem', padding: '1rem' }}>
39-
This panel on the other hand has the lightest border on the edge. Use
40-
this panel inside &apos;outside&apos; panels.
39+
<Frame variant='inside' style={{ margin: '1rem', padding: '1rem' }}>
40+
This frame of the &apos;button&apos; variant on the other hand has the
41+
lightest border on the edge. Use this frame inside &apos;window&apos;
42+
frames.
4143
<br />
42-
<Panel
43-
variant='well'
44+
<Frame
45+
variant='field'
4446
style={{
4547
marginTop: '1rem',
4648
padding: '1rem',
4749
height: 200,
4850
width: 100
4951
}}
5052
>
51-
Put some content here
52-
</Panel>
53-
</Panel>
54-
<Panel
53+
A field frame variant is used to display content.
54+
</Frame>
55+
</Frame>
56+
<Frame
5557
variant='well'
5658
style={{ marginTop: '1rem', padding: '0.1rem 0.25rem', width: '100%' }}
5759
>
58-
The &apos;well&apos; variant of a panel is often used as a window
59-
footer.
60-
</Panel>
61-
</Panel>
60+
The &apos;status&apos; variant of a frame is often used as a status bar
61+
at the end of the window.
62+
</Frame>
63+
</Frame>
6264
);
6365
}
6466

src/Frame/Frame.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import React, { forwardRef } from 'react';
2+
import styled, { css } from 'styled-components';
3+
import { createBorderStyles, createBoxStyles } from '../common';
4+
import { CommonStyledProps } from '../types';
5+
6+
type FrameProps = {
7+
children?: React.ReactNode;
8+
shadow?: boolean;
9+
variant?: 'outside' | 'field' | 'inside' | 'well';
10+
} & React.HTMLAttributes<HTMLDivElement> &
11+
CommonStyledProps;
12+
13+
const createFrameStyles = (variant: FrameProps['variant']) => {
14+
switch (variant) {
15+
case 'well':
16+
return css`
17+
${createBorderStyles({ style: 'status' })}
18+
`;
19+
case 'outside':
20+
return css`
21+
${createBorderStyles({ style: 'window' })}
22+
`;
23+
case 'field':
24+
return css`
25+
${createBorderStyles({ style: 'field' })}
26+
`;
27+
default:
28+
return css`
29+
${createBorderStyles()}
30+
`;
31+
}
32+
};
33+
34+
const StyledFrame = styled.div<Required<Pick<FrameProps, 'variant'>>>`
35+
position: relative;
36+
font-size: 1rem;
37+
${({ variant }) => createFrameStyles(variant)}
38+
${({ variant }) =>
39+
createBoxStyles(
40+
variant === 'field'
41+
? { background: 'canvas', color: 'canvasText' }
42+
: undefined
43+
)}
44+
`;
45+
46+
const Frame = forwardRef<HTMLDivElement, FrameProps>(
47+
({ children, shadow = false, variant = 'window', ...otherProps }, ref) => {
48+
return (
49+
<StyledFrame ref={ref} shadow={shadow} variant={variant} {...otherProps}>
50+
{children}
51+
</StyledFrame>
52+
);
53+
}
54+
);
55+
56+
Frame.displayName = 'Frame';
57+
58+
export { Frame, FrameProps };

src/MenuList/MenuList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const MenuList = styled.ul.attrs(() => ({
1717
box-sizing: border-box;
1818
width: ${props => (props.fullWidth ? '100%' : 'auto')};
1919
padding: 4px;
20-
${createBorderStyles({ windowBorders: true })}
20+
${createBorderStyles({ style: 'window' })}
2121
${createBoxStyles()}
2222
${props =>
2323
props.inline &&

src/Panel/Panel.spec.tsx

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/Panel/Panel.tsx

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/TableHeadCell/TableHeadCell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const StyledHeadCell = styled.th<{ $disabled: boolean }>`
3737
css`
3838
&:active {
3939
&:before {
40-
${createBorderStyles({ invert: true, windowBorders: true })}
40+
${createBorderStyles({ invert: true, style: 'window' })}
4141
border-left: none;
4242
border-top: none;
4343
padding-top: 2px;

0 commit comments

Comments
 (0)