Skip to content

Commit

Permalink
Merge pull request #193 from ynput/develop
Browse files Browse the repository at this point in the history
Release: EntityCard priority and notifications
  • Loading branch information
Innders authored Oct 3, 2024
2 parents 313a1a4 + dcc6b6f commit 3a06d39
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 303 deletions.
11 changes: 7 additions & 4 deletions src/Dropdowns/EnumDropdown/EnumDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const EnumTemplate = ({ option, isSelected, isChanged, ...props }: EnumTe
return (
<Styled.Option
className={clsx({ selected: isSelected, isChanged }, props.className)}
id={value}
id={String(value)}
$color={color}
{...props}
>
Expand All @@ -26,20 +26,21 @@ export const EnumTemplate = ({ option, isSelected, isChanged, ...props }: EnumTe
}

export type EnumDropdownOption = {
value: string
value: string | number | boolean
label: string
icon?: IconType
color?: string
}

export interface EnumDropdownProps
extends Omit<DropdownProps, 'options' | 'valueTemplate' | 'itemTemplate' | 'ref'> {
extends Omit<DropdownProps, 'value' | 'options' | 'valueTemplate' | 'itemTemplate' | 'ref'> {
options: EnumDropdownOption[]
colorInverse?: boolean
value: (string | number | boolean)[]
}

export const EnumDropdown = forwardRef<DropdownRef, EnumDropdownProps>(
({ colorInverse, ...props }, ref) => {
({ colorInverse, value, ...props }, ref) => {
return (
<Dropdown
ref={ref}
Expand All @@ -49,6 +50,7 @@ export const EnumDropdown = forwardRef<DropdownRef, EnumDropdownProps>(
<Styled.StyledDefaultValueTemplate
isOpen={o}
{...props}
value={value?.map((v) => String(v))}
$color={props.isChanged ? undefined : option?.color} // use color (but not when in changed state - editor)
className={clsx({ inverse: colorInverse })}
>
Expand All @@ -59,6 +61,7 @@ export const EnumDropdown = forwardRef<DropdownRef, EnumDropdownProps>(
itemTemplate={(option, isSelected) => (
<EnumTemplate option={option} isSelected={isSelected} style={{ paddingLeft: '0.5rem' }} />
)}
value={value?.map((v) => String(v))}
{...props}
/>
)
Expand Down
19 changes: 10 additions & 9 deletions src/EntityCard/EntityCard.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { Meta, StoryObj } from '@storybook/react'
import { EntityCard, EntityCardProps, PriorityType } from '.'
import { MouseEvent, useEffect, useState } from 'react'
import { Toolbar } from '../Layout/Toolbar'
import { EntityCard, EntityCardProps } from '.'
import { MouseEvent, useState } from 'react'
import { Button } from '../Button'
import { Panel } from '../Panels/Panel'
import DnDTemplate from './DnD/DnDTemplate'
import getRandomImage from '../helpers/getRandomImage'
import styled from 'styled-components'
import clsx from 'clsx'
import { allUsers } from '../Dropdowns/helpers'
import prioritiesData from './priorities.json'
import { randomStatus, statuses } from '../Dropdowns/StatusSelect'
import { EnumDropdownOption } from '../Dropdowns/EnumDropdown'

const meta: Meta<typeof EntityCard> = {
component: EntityCard,
Expand All @@ -23,7 +22,7 @@ type Story = StoryObj<typeof EntityCard>

interface DataProps extends EntityCardProps {}

const priorities = prioritiesData as PriorityType[]
const priorities = prioritiesData as EnumDropdownOption[]

// pick 1 - 3 users randomly from the array
const randomUsers = allUsers
Expand All @@ -38,7 +37,7 @@ const Template = ({ onActivate, ...props }: TemplateProps) => {
const [isActive, setIsActive] = useState(false)
return (
<div style={{ display: 'flex', gap: 16 }}>
<div style={{ width: 250 }}>
<div style={{ width: '100%', maxWidth: 210 }}>
<EntityCard
isActive={isActive}
onActivate={() => {
Expand All @@ -58,6 +57,7 @@ const StatusWrapper = styled.div`
`

const StyledCell = styled.div`
width: 250px;
padding: 8px;
background-color: var(--md-sys-color-surface-container-low);
border: 1px solid var(--md-sys-color-outline-variant);
Expand All @@ -77,15 +77,15 @@ const StatusTemplate = (props: TemplateProps) => {

const [selectedUsers, setSelectedUsers] = useState(props.users?.map((u) => u.name) || [])
const [selectedStatus, setSelectedStatus] = useState(props.status?.name)
const [selectedPriority, setSelectedPriority] = useState(props.priority?.name)
const [selectedPriority, setSelectedPriority] = useState(props.priority?.value)

const handleChange = (change: any, key: string) => {
console.log('changed:', change, key)
}

const users = props.assigneeOptions?.filter((u) => selectedUsers.includes(u.name)) || []
const status = statuses.find((s) => s.name === selectedStatus)
const priority = priorities.find((p) => p.name === selectedPriority)
const priority = priorities.find((p) => p.value === selectedPriority)

const handleCellClick = (e: MouseEvent<HTMLDivElement>) => {
// check if the click is editable item
Expand Down Expand Up @@ -167,6 +167,7 @@ const initData: DataProps = {
export const Default: Story = {
args: {
...initData,
notification: { comment: true },
},
render: Template,
}
Expand All @@ -182,7 +183,6 @@ export const Loading: Story = {
export const TaskStatus: Story = {
args: {
variant: 'status',
notification: undefined,
disabled: false,
...initData,
isPlayable: false,
Expand All @@ -204,6 +204,7 @@ export const ProgressView: Story = {
statusOptions: statuses,
statusMiddle: true,
statusNameOnly: true,
isPlayable: true,
},
render: (args) => <StatusTemplate {...args} />,
}
Expand Down
12 changes: 4 additions & 8 deletions src/EntityCard/EntityCard.styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const cardHoverStyles = css`
}
`

export const Wrapper = styled.div`
position: relative;
`

type CardProps = {
$statusColor?: string
}
Expand Down Expand Up @@ -284,9 +288,6 @@ export const Card = styled.div<CardProps>`
container-type: inline-size;
/* use container query for when the card gets smaller */
@container card (inline-size < 150px) {
.playable {
display: none;
}
.title {
.icon {
display: none;
Expand All @@ -296,11 +297,6 @@ export const Card = styled.div<CardProps>`
}
}
}
@container card (inline-size < 100px) {
.playable {
display: none;
}
}
/* hide everything on bottom but the status icon */
@container card (inline-size < 85px) {
Expand Down
Loading

0 comments on commit 3a06d39

Please sign in to comment.