Skip to content

Commit d86f4a9

Browse files
authored
Merge pull request #178 from seamapi/pr-followups-2
Followups to pull requests
2 parents dfeec5d + 41d77d6 commit d86f4a9

27 files changed

+130
-131
lines changed

examples/basic/src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createRoot } from 'react-dom/client'
33

44
import { App } from './App.js'
55

6-
const rootElement = document.getElementById('root')
6+
const rootElement = globalThis.document.getElementById('root')
77

88
if (rootElement == null) throw new Error('Root element not found')
99

src/lib/copy-to-clipboard.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export async function copyToClipboard(value: string) {
2+
await globalThis?.navigator?.clipboard?.writeText(value)
3+
}

src/lib/copy.ts

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

src/lib/ui/AccessCodeDetails/AccessCodeDetails.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Button, Dialog } from '@mui/material'
22
import type { Meta, StoryObj } from '@storybook/react'
33

44
import { AccessCodeDetails } from 'lib/ui/AccessCodeDetails/AccessCodeDetails.js'
5-
import useToggle from 'lib/use-toggle.js'
5+
import { useToggle } from 'lib/use-toggle.js'
66

77
/**
88
* These stories showcase access code details.

src/lib/ui/AccessCodeTable/AccessCodeTable.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Button, Dialog } from '@mui/material'
22
import type { Meta, StoryObj } from '@storybook/react'
33

44
import { AccessCodeTable } from 'lib/ui/AccessCodeTable/AccessCodeTable.js'
5-
import useToggle from 'lib/use-toggle.js'
5+
import { useToggle } from 'lib/use-toggle.js'
66

77
/**
88
* These stories showcase the access code table.

src/lib/ui/AccessCodeTable/AccessCodeTable.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from 'react'
22
import type { AccessCode } from 'seamapi'
33

4-
import { copy } from 'lib/copy.js'
4+
import { copyToClipboard } from 'lib/copy-to-clipboard.js'
55
import { AccessCodeKeyIcon } from 'lib/icons/AccessCodeKey.js'
66
import { CopyIcon } from 'lib/icons/Copy.js'
77
import {
@@ -112,15 +112,15 @@ function AccessCodeRow(props: {
112112
</TableCell>
113113
<TableCell className='seam-action-cell'>
114114
<MoreActionsMenu
115-
MenuProps={{
116-
BackgroundProps: {
115+
menuProps={{
116+
backgroundProps: {
117117
className: 'seam-access-code-table-action-menu',
118118
},
119119
}}
120120
>
121121
<MenuItem
122122
onClick={() => {
123-
void copy(accessCode.code ?? '')
123+
void copyToClipboard(accessCode.code ?? '')
124124
}}
125125
>
126126
<div className='menu-item-copy'>

src/lib/ui/Alert/Alert.tsx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@ import { TriangleWarningIcon } from 'lib/icons/TriangleWarning.js'
77
export interface AlertProps {
88
variant: 'warning' | 'error'
99
message: string
10-
action?: {
11-
label: string
12-
onClick: MouseEventHandler
13-
}
10+
action?: ActionProps
1411
className?: string
1512
}
1613

17-
export function Alert(props: AlertProps): JSX.Element {
18-
const { variant, message, action, className, ...rest } = props
14+
interface ActionProps {
15+
label: string
16+
onClick: MouseEventHandler
17+
}
1918

20-
const handleClick: MouseEventHandler<HTMLButtonElement> = (ev) => {
21-
action?.onClick(ev)
22-
}
19+
export function Alert(props: AlertProps): JSX.Element {
20+
const { variant, message, className } = props
2321

2422
return (
2523
<div
2624
className={classNames('seam-alert', `seam-${variant}-alert`, className)}
27-
{...rest}
2825
>
2926
<div className='seam-alert-content'>
3027
<div className='seam-alert-icon'>
@@ -34,19 +31,25 @@ export function Alert(props: AlertProps): JSX.Element {
3431
<ExclamationCircleIcon />
3532
)}
3633
</div>
37-
3834
<div className='seam-alert-message-wrap'>
3935
<p className='seam-alert-message'>{message}</p>
4036
</div>
4137
</div>
38+
{props.action == null ? null : <Action {...props.action} />}
39+
</div>
40+
)
41+
}
4242

43-
{action != null && (
44-
<div className='seam-alert-action-wrap'>
45-
<button onClick={handleClick} className='seam-alert-action'>
46-
{action.label}
47-
</button>
48-
</div>
49-
)}
43+
function Action(props: ActionProps): JSX.Element | null {
44+
const handleClick: MouseEventHandler<HTMLButtonElement> = (event) => {
45+
props.onClick(event)
46+
}
47+
48+
return (
49+
<div className='seam-alert-action-wrap'>
50+
<button onClick={handleClick} className='seam-alert-action'>
51+
{props.label}
52+
</button>
5053
</div>
5154
)
5255
}

src/lib/ui/Alert/Alerts.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ import classNames from 'classnames'
22

33
import { Alert, type AlertProps } from 'lib/ui/Alert/Alert.js'
44

5-
export interface AlertsProps {
5+
interface AlertsProps {
66
alerts?: AlertProps[]
7-
children?: React.ReactNode
7+
children?: JSX.Element
88
className?: string
99
}
1010

11-
export function Alerts(props: AlertsProps): JSX.Element {
12-
const { alerts, children, className, ...rest } = props
11+
export function Alerts(props: AlertsProps): JSX.Element | null {
12+
const { alerts, children, className } = props
13+
14+
if (alerts?.length === 0) return null
1315

1416
return (
15-
<div className={classNames('seam-alerts', className)} {...rest}>
17+
<div className={classNames('seam-alerts', className)}>
1618
{alerts?.map((alert, index) => (
1719
<Alert key={`${index}:${alert.message}`} {...alert} />
1820
))}

src/lib/ui/DeviceDetails/DeviceDetails.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Button, Dialog, DialogActions, IconButton } from '@mui/material'
33
import type { Meta, StoryObj } from '@storybook/react'
44

55
import { DeviceDetails } from 'lib/ui/DeviceDetails/DeviceDetails.js'
6-
import useToggle from 'lib/use-toggle.js'
6+
import { useToggle } from 'lib/use-toggle.js'
77

88
/**
99
* These stories showcase the device details.

src/lib/ui/DeviceDetails/DeviceDetails.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { useAccessCodes } from 'lib/seam/access-codes/use-access-codes.js'
77
import { isLockDevice } from 'lib/seam/devices/types.js'
88
import { useToggleLock } from 'lib/seam/devices/use-toggle-lock.js'
99
import { AccessCodeTable } from 'lib/ui/AccessCodeTable/AccessCodeTable.js'
10-
import { type AlertProps } from 'lib/ui/Alert/Alert.js'
10+
import type { AlertProps } from 'lib/ui/Alert/Alert.js'
1111
import { Alerts } from 'lib/ui/Alert/Alerts.js'
1212
import { Button } from 'lib/ui/Button.js'
1313
import { BatteryStatus } from 'lib/ui/device/BatteryStatus.js'
1414
import { DeviceImage } from 'lib/ui/device/DeviceImage.js'
1515
import { OnlineStatus } from 'lib/ui/device/OnlineStatus.js'
1616
import { DeviceModel } from 'lib/ui/DeviceDetails/DeviceModel.js'
1717
import { ContentHeader } from 'lib/ui/layout/ContentHeader.js'
18-
import useToggle from 'lib/use-toggle.js'
18+
import { useToggle } from 'lib/use-toggle.js'
1919

2020
export interface DeviceDetailsProps {
2121
deviceId: string
@@ -121,10 +121,7 @@ function LockDeviceDetails(props: { device: LockDevice; onBack?: () => void }) {
121121
</div>
122122
</div>
123123
</div>
124-
125-
{alerts.length > 0 && (
126-
<Alerts alerts={alerts} className='seam-alerts-space-top' />
127-
)}
124+
<Alerts alerts={alerts} className='seam-alerts-space-top' />
128125
</div>
129126
<div className='seam-box'>
130127
<div

0 commit comments

Comments
 (0)