Skip to content

Commit

Permalink
feat(core): TaskBar revisited!
Browse files Browse the repository at this point in the history
  • Loading branch information
ggdaltoso committed Feb 9, 2024
1 parent 6b60082 commit 51d64db
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 126 deletions.
3 changes: 2 additions & 1 deletion packages/core/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ImageLoader } from 'esbuild-vanilla-image-loader';
export default {
// stories: [, '../stories/(?!all)*.stories.tsx'],
stories: [
'../stories/taskbar.stories.tsx',
'../stories/tooltip.stories.tsx',
'../stories/radiobutton.stories.tsx',
'../stories/titlebar.stories.tsx',
Expand Down Expand Up @@ -33,8 +34,8 @@ export default {
{
name: '@storybook/addon-essentials',
options: {
controls: true,
actions: false,
controls: false,
},
},
'@storybook/addon-storysource',
Expand Down
25 changes: 8 additions & 17 deletions packages/core/components/TaskBar/Clock.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import React, { useEffect, useState } from 'react';
import styled from '@xstyled/styled-components';

import Frame from '../Frame';
import Tooltip from '../Tooltip';

const StyledTooltip = styled(Tooltip)`
div:first-child {
right: 0;
}
`;
import { tooltip } from './TaskBar.css';

const Clock = () => {
const [timer, setTimer] = useState('');
Expand All @@ -30,17 +24,14 @@ const Clock = () => {

return (
<Frame
boxShadow="in"
bg="transparent"
px={6}
py={2}
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}
boxShadow="$in"
px="$6"
py="$2"
display="flex"
justifyContent="center"
alignItems="center"
>
<StyledTooltip>{timer}</StyledTooltip>
<Tooltip className={tooltip}>{timer}</Tooltip>
</Frame>
);
};
Expand Down
85 changes: 85 additions & 0 deletions packages/core/components/TaskBar/TaskBar.css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { globalStyle, style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
import { contract } from '../ThemeProvider/themes/contract.css';
import { calc } from '@vanilla-extract/css-utils';

export const truncate = style({
overflow: 'hidden',
display: '-webkit-box',
WebkitLineClamp: '1',
WebkitBoxOrient: 'vertical',
textAlign: 'left',
});

export const tooltip = style({});

globalStyle(`${tooltip} div:first-child`, {
right: 0,
});

export const windowsButton = recipe({
base: {
display: 'inline-flex',
justifyContent: 'flex-start',
alignItems: 'center',
backgroundColor: contract.colors.material,
paddingBlock: contract.space[2],
paddingInline: contract.space[3],
marginRight: contract.space[2],
maxWidth: '150px',
border: 'none',
outline: 'none',
},
variants: {
small: {
true: {
paddingInline: contract.space[5],
},
false: {
width: '100%',
},
},
active: {
true: {
boxShadow: contract.shadows.in,
},
false: {
boxShadow: contract.shadows.out,
},
},
},
compoundVariants: [
{
variants: {
active: true,
small: true,
},
style: {
paddingTop: contract.space[4],
paddingBottom: contract.space[0],
outline: `${contract.space[1]} dotted ${contract.colors.borderDarkest}`,
outlineOffset: calc.negate(contract.space[4]),
},
},
{
variants: {
active: true,
small: false,
},
style: {
backgroundColor: contract.colors.borderLighter,
},
},
],
});

export const icon = style({});

globalStyle(`${icon} svg`, {
marginTop: contract.space[4],
marginRight: contract.space[4],
minWidth: contract.space[2],
width: contract.space[20],
height: contract.space[20],
shapeRendering: 'auto',
});
44 changes: 16 additions & 28 deletions packages/core/components/TaskBar/TaskBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* eslint-disable react/no-array-index-key */
import React, { forwardRef } from 'react';
import styled from '@xstyled/styled-components';
import React, { forwardRef, useContext, useState } from 'react';

import { ModalContext } from '../Modal';
import Frame from '../Frame';
Expand All @@ -9,43 +7,37 @@ import List from '../List';
import Clock from './Clock';
import WindowButton from './WindowButton';
import { Logo } from '@react95/icons';

const Truncate = styled.span`
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
text-align: left;
`;
import { truncate } from './TaskBar.css';

export type TaskBarProps = {
list?: React.ReactElement<typeof List>;
};

const TaskBar = forwardRef<HTMLDivElement, TaskBarProps>(({ list }, ref) => {
const [showList, toggleShowList] = React.useState(false);
const [activeStart, toggleActiveStart] = React.useState(false);
const { windows, activeWindow, setActiveWindow } =
React.useContext(ModalContext);
const [showList, toggleShowList] = useState(false);
const [activeStart, toggleActiveStart] = useState(false);
const { windows, activeWindow, setActiveWindow } = useContext(ModalContext);

return (
<Frame
position="fixed"
bottom={0}
left={0}
right={0}
bottom="0px"
left="0px"
right="0px"
display="flex"
justifyContent="space-between"
h={28}
h="28px"
w="100%"
padding={2}
zIndex="taskbar"
padding="$2"
zIndex="$taskbar"
backgroundColor="$material"
boxShadow="$out"
ref={ref}
>
{showList && (
<Frame
position="absolute"
bottom="28"
bottom="28px"
onClick={() => {
toggleActiveStart(false);
toggleShowList(false);
Expand All @@ -66,7 +58,7 @@ const TaskBar = forwardRef<HTMLDivElement, TaskBarProps>(({ list }, ref) => {
Start
</WindowButton>

<Frame boxShadow="none" w="100%" paddingLeft={0} ml={2} display="flex">
<Frame w="100%" paddingLeft="$0" ml="$2" display="flex">
{Object.entries(windows).map(
([windowId, { icon, title, hasButton }]) =>
hasButton && (
Expand All @@ -77,7 +69,7 @@ const TaskBar = forwardRef<HTMLDivElement, TaskBarProps>(({ list }, ref) => {
onClick={() => setActiveWindow(windowId)}
small={false}
>
<Truncate>{title}</Truncate>
<div className={truncate}>{title}</div>
</WindowButton>
),
)}
Expand All @@ -88,8 +80,4 @@ const TaskBar = forwardRef<HTMLDivElement, TaskBarProps>(({ list }, ref) => {
);
});

TaskBar.defaultProps = {
list: undefined,
};

export default TaskBar;
95 changes: 15 additions & 80 deletions packages/core/components/TaskBar/WindowButton.tsx
Original file line number Diff line number Diff line change
@@ -1,90 +1,25 @@
import React from 'react';
import styled, { css, th } from '@xstyled/styled-components';
import { Bat } from '@react95/icons';
import React, { forwardRef } from 'react';

import Frame, { FrameProps } from '../Frame/Frame';
import { Windows } from '../Modal/ModalContext';
import * as styles from './TaskBar.css';

export type WindowButtonProps = {
small?: boolean;
active?: boolean;
} & Pick<Windows, 'icon'> &
React.HTMLAttributes<HTMLButtonElement> &
FrameProps;

type ButtonFrameProps = Omit<WindowButtonProps, 'icon'>;

const Button = styled(Frame)<ButtonFrameProps>`
display: inline-flex;
justify-content: flex-start;
align-items: center;
padding: 2 3;
margin-right: 2;
max-width: 150px;
border: none;
outline: none;
${({ small }) =>
!small
? `
width: 100%;
`
: ''}
${({ active, small }) =>
active && small
? css`
outline: ${th('space.1')}px dotted ${th('colors.borderDarkest')};
outline-offset: -${th('space.4')}px;
padding-top: 4;
padding-right: 2;
padding-bottom: 0;
padding-left: 4;
`
: ''}
`;

const IconWrapper = styled.div`
svg {
margin-top: 4;
margin-right: 4;
min-width: 20;
width: 20;
height: 20;
shape-rendering: auto;
}
`;

const WindowButton: React.FC<WindowButtonProps> = ({
children = '',
small,
icon,
active,
...props
}) => (
<Button
active={active}
small={small}
{...(active
? {
boxShadow: 'in',
bg: small ? undefined : 'borderLighter',
}
: {
boxShadow: 'out',
})}
{...props}
as="button"
>
<IconWrapper>{icon}</IconWrapper>
{children}
</Button>
React.ButtonHTMLAttributes<HTMLButtonElement>;

const WindowButton = forwardRef<HTMLButtonElement, WindowButtonProps>(
({ children, small = false, icon, active = false, ...props }, ref) => (
<button
className={styles.windowsButton({ active, small })}
{...props}
ref={ref}
>
<div className={styles.icon}>{icon}</div>
{children}
</button>
),
);

WindowButton.defaultProps = {
small: false,
icon: <Bat variant="32x32_4" />,
active: false,
};

export default WindowButton;

0 comments on commit 51d64db

Please sign in to comment.