onOpenChange(!isOpen)}
+ onClick={() => onOpenChange?.(!isOpen)}
>
{label}
diff --git a/assets/design-system/src/components/ChecklistItem.tsx b/assets/design-system/src/components/ChecklistItem.tsx
index 9c5263a2d9..2879257871 100644
--- a/assets/design-system/src/components/ChecklistItem.tsx
+++ b/assets/design-system/src/components/ChecklistItem.tsx
@@ -170,7 +170,7 @@ type ChecklistItemInnerProps = Omit
& {
selected?: boolean
focused?: boolean
completed?: boolean
- onSelectionChange: Dispatch
+ onSelectionChange: Dispatch
onFocusChange: Dispatch
}
@@ -184,7 +184,7 @@ function ChecklistItemInnerUnstyled({
onFocusChange,
...props
}: ChecklistItemInnerProps): JSX.Element {
- const headerRef = useRef(undefined)
+ const headerRef = useRef(null)
const { keyboardProps } = useKeyboard({
onKeyDown: (e) => {
switch (e.key) {
@@ -209,7 +209,7 @@ function ChecklistItemInnerUnstyled({
useEffect(() => {
if (headerRef.current && focused) {
- setTimeout(() => headerRef.current.focus())
+ setTimeout(() => headerRef.current?.focus())
}
}, [headerRef, focused])
diff --git a/assets/design-system/src/components/ChipList.tsx b/assets/design-system/src/components/ChipList.tsx
index 02faa4915a..dfe7134d23 100644
--- a/assets/design-system/src/components/ChipList.tsx
+++ b/assets/design-system/src/components/ChipList.tsx
@@ -40,7 +40,7 @@ function ChipList({
clickable && onClick(v)}
+ onClick={() => clickable && onClick?.(v)}
{...props}
>
{transformValue ? transformValue(v) : `${v}`}
diff --git a/assets/design-system/src/components/Code.tsx b/assets/design-system/src/components/Code.tsx
index ce8e25d872..b383731bb8 100644
--- a/assets/design-system/src/components/Code.tsx
+++ b/assets/design-system/src/components/Code.tsx
@@ -58,7 +58,7 @@ type CodeProps = Omit & {
type TabInterfaceT = 'tabs' | 'dropdown'
type TabsContext = {
- tabInterface: TabInterfaceT
+ tabInterface?: TabInterfaceT
setTabInterface: (arg: TabInterfaceT) => void
tabStateRef?: RefObject
selectedKey?: string
@@ -206,12 +206,13 @@ function CodeTabs() {
setTabInterface,
tabStateRef,
- tabs,
+ tabs: tabsProp,
selectedKey,
onSelectionChange,
} = useContext(TabsContext)
- const tabsRef = useRef(undefined)
- const tabsWrapRef = useRef(undefined)
+ const tabs = tabsProp ?? []
+ const tabsRef = useRef(null)
+ const tabsWrapRef = useRef(null)
const tabListStateProps: TabListStateProps = {
keyboardActivation: 'manual',
orientation: 'horizontal',
@@ -236,10 +237,12 @@ function CodeTabs() {
}, [setTabInterface])
)
+ if (!tabStateRef) return null
+
return (
) {
- const { tabs, selectedKey, onSelectionChange } = useContext(TabsContext)
+ const {
+ tabs: tabsProp,
+ selectedKey,
+ onSelectionChange,
+ } = useContext(TabsContext)
+ const tabs = tabsProp ?? []
const selectedTab = tabs.find((tab) => tab.key === selectedKey) || tabs[0]
@@ -283,7 +291,7 @@ function CodeSelectUnstyled({ className }: ComponentProps<'div'>) {
width="max-content"
placement="right"
triggerButton={
- {selectedTab.label}
+ {selectedTab?.label}
}
>
{tabs.map((tab) => (
@@ -409,12 +417,12 @@ function CodeUnstyled({
}: CodeProps) {
const parentFillLevel = useFillLevel()
const inferredFillLevel = fillLevelProp ?? parentFillLevel
- const tabStateRef = useRef(undefined)
+ const tabStateRef = useRef(null)
const [selectedTabKey, setSelectedTabKey] = useState(
tabs?.[0]?.key || ''
)
const theme = useTheme()
- const [tabInterface, setTabInterface] = useState()
+ const [tabInterface, setTabInterface] = useState()
props.height = props.height || undefined
const hasSetHeight = !!props.height || !!props.minHeight
@@ -508,7 +516,7 @@ function CodeUnstyled({
isStreaming={isStreaming}
setMermaidError={setMermaidError}
>
- {children}
+ {children ?? ''}
)}
diff --git a/assets/design-system/src/components/CodeEditor.tsx b/assets/design-system/src/components/CodeEditor.tsx
index e761476cb4..fe0411b026 100644
--- a/assets/design-system/src/components/CodeEditor.tsx
+++ b/assets/design-system/src/components/CodeEditor.tsx
@@ -49,9 +49,9 @@ export default function CodeEditor({
const parentFillLevel = useFillLevel()
const theme = useTheme()
const monaco = useMonaco()
- const [current, setCurrent] = useState(value)
+ const [current, setCurrent] = useState(value ?? '')
const [copied, setCopied] = useState(false)
- const changed = current !== value
+ const changed = current !== (value ?? '')
const onEditorMount = useCallback(
(editor: any) => {
@@ -115,8 +115,8 @@ export default function CodeEditor({
language={language}
value={value}
onChange={(v) => {
- setCurrent(v)
- if (onChange) onChange(v)
+ setCurrent(v ?? '')
+ if (onChange) onChange(v ?? '')
}}
options={mergedOptions}
theme={theme.mode === 'light' ? 'plural-light' : 'plural-dark'}
diff --git a/assets/design-system/src/components/ComboBox.tsx b/assets/design-system/src/components/ComboBox.tsx
index 0bb8df94b8..ec09941389 100644
--- a/assets/design-system/src/components/ComboBox.tsx
+++ b/assets/design-system/src/components/ComboBox.tsx
@@ -105,20 +105,22 @@ const OpenButtonSC = styled.div(({ theme }) => ({
function OpenButton({
buttonRef,
- buttonProps,
+ buttonProps = {},
...props
}: HTMLAttributes & {
- buttonRef: RefObject
- buttonProps: AriaButtonProps
+ buttonRef?: RefObject
+ buttonProps?: AriaButtonProps
}) {
+ const fallbackRef = useRef(null)
+ const resolvedButtonRef = buttonRef ?? fallbackRef
const { buttonProps: useButtonProps } = useButton(
{ ...buttonProps, elementType: 'div' },
- buttonRef
+ resolvedButtonRef
)
return (
@@ -237,7 +239,7 @@ function ComboBox({
containerProps,
...props
}: ComboBoxProps) {
- const nextFocusedKeyRef = useRef(null)
+ const nextFocusedKeyRef = useRef(null)
const stateRef = useRef | null>(null)
const [isOpenUncontrolled, setIsOpenUncontrolled] = useState(false)
const previousInputValue = useRef(inputValue)
@@ -246,7 +248,7 @@ function ComboBox({
isOpen = isOpenUncontrolled
}
- const wrappedOnOpenChange: typeof onOpenChange = useCallback(
+ const wrappedOnOpenChange: NonNullable = useCallback(
(nextIsOpen, menuTrigger) => {
setIsOpenUncontrolled(nextIsOpen)
if (nextIsOpen !== isOpen) {
@@ -263,40 +265,38 @@ function ComboBox({
[wrappedOnOpenChange]
)
- const wrappedOnSelectionChange: typeof onSelectionChange = useCallback(
- (newKey, ...args) => {
- if (onSelectionChange) {
- onSelectionChange.apply(this, [
- typeof newKey === 'string' ? newKey : '',
- ...args,
- ])
- setIsOpen(false)
- }
- },
- [onSelectionChange, setIsOpen]
- )
+ const wrappedOnSelectionChange: NonNullable =
+ useCallback(
+ (newKey) => {
+ if (onSelectionChange) {
+ onSelectionChange(typeof newKey === 'string' ? newKey : '')
+ setIsOpen(false)
+ }
+ },
+ [onSelectionChange, setIsOpen]
+ )
- const wrappedOnFocusChange: typeof onFocusChange = useCallback(
- (isFocused, ...args) => {
+ const wrappedOnFocusChange: NonNullable = useCallback(
+ (isFocused) => {
// Enforce open on focus
if (isFocused && !isOpen) {
setIsOpen(true)
}
if (onFocusChange) {
- onFocusChange(isFocused, ...args)
+ onFocusChange(isFocused)
}
},
[isOpen, onFocusChange, setIsOpen]
)
- const wrappedOnInputChange: typeof onInputChange = useCallback(
- (input, ...args) => {
+ const wrappedOnInputChange: NonNullable = useCallback(
+ (input) => {
if (input !== previousInputValue.current) {
previousInputValue.current = input
setIsOpen(true)
}
if (onInputChange) {
- onInputChange(input, ...args)
+ onInputChange(input)
}
},
[onInputChange, setIsOpen]
@@ -341,16 +341,16 @@ function ComboBox({
}
}, [state, isOpen])
- const buttonRef = useRef(null)
- const inputRef = useRef(null)
- const inputInnerRef = useRef(null)
- const listBoxRef = useRef(null)
- const popoverRef = useRef(null)
+ const buttonRef = useRef(null)
+ const triggerElRef = useRef(null)
+ const inputInnerRef = useRef(null)
+ const listBoxRef = useRef(null)
+ const popoverRef = useRef(null)
const { buttonProps, inputProps, listBoxProps } = useComboBox(
{
...comboStateProps,
- inputRef,
+ inputRef: inputInnerRef,
buttonRef,
listBoxRef,
popoverRef,
@@ -363,7 +363,7 @@ function ComboBox({
}
const { floating, triggerRef } = useFloatingDropdown({
- triggerRef: inputRef,
+ triggerRef: triggerElRef,
width,
maxHeight,
placement,
@@ -390,7 +390,7 @@ function ComboBox({
if (nextChipClose instanceof HTMLElement) {
nextChipClose.focus?.()
} else {
- inputRef.current?.querySelector('input')?.focus?.()
+ inputInnerRef.current?.focus?.()
}
}
@@ -424,20 +424,24 @@ function ComboBox({
) {
const chip = document.activeElement?.closest(`[${CHIP_ATTR_KEY}]`)
+ if (!chip) return
+
if (dir === 1) {
if (!chip.nextElementSibling) {
inputInnerRef.current?.focus()
} else {
- chip?.nextElementSibling
- ?.querySelector(`[${CHIP_CLOSE_ATTR_KEY}]`)
- // @ts-ignore
- ?.focus?.()
+ ;(
+ chip.nextElementSibling.querySelector(
+ `[${CHIP_CLOSE_ATTR_KEY}]`
+ ) as HTMLElement | null
+ )?.focus?.()
}
} else if (dir === -1) {
- chip.previousElementSibling
- ?.querySelector(`[${CHIP_CLOSE_ATTR_KEY}]`)
- // @ts-ignore
- ?.focus?.()
+ ;(
+ chip.previousElementSibling?.querySelector(
+ `[${CHIP_CLOSE_ATTR_KEY}]`
+ ) as HTMLElement | null
+ )?.focus?.()
}
}
}, [])
@@ -452,7 +456,7 @@ function ComboBox({
ref={chipListRef}
onKeyDown={handleKeyDown}
>
- {chips.map((chipProps) => (
+ {chips?.map((chipProps) => (
({
function EmptyState({
message,
description,
- icon = null,
+ icon,
children,
...props
}: EmptyStateProps) {
diff --git a/assets/design-system/src/components/Flex.tsx b/assets/design-system/src/components/Flex.tsx
index 448412519c..4bfc9afa9f 100644
--- a/assets/design-system/src/components/Flex.tsx
+++ b/assets/design-system/src/components/Flex.tsx
@@ -72,7 +72,7 @@ function BaseFlex({
return (
}
+ wrapper={}
>
children.split(/\r?\n/), [children])
useLayoutEffect(() => {
- if (hljs.getLanguage(language) && codeRef.current) {
+ if (language && hljs.getLanguage(language) && codeRef.current) {
delete codeRef.current.dataset.highlighted
hljs.highlightElement(codeRef.current)
}
diff --git a/assets/design-system/src/components/IconFrame.tsx b/assets/design-system/src/components/IconFrame.tsx
index e7af163958..c68bab9824 100644
--- a/assets/design-system/src/components/IconFrame.tsx
+++ b/assets/design-system/src/components/IconFrame.tsx
@@ -15,7 +15,7 @@ import Tooltip, { type TooltipProps } from './Tooltip'
type Size = 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge'
type Type = 'secondary' | 'tertiary' | 'floating'
-function typeToBG(theme: DefaultTheme): Record {
+function typeToBG(theme: DefaultTheme): Record {
return {
secondary: 'transparent',
tertiary: 'transparent',
@@ -26,7 +26,7 @@ function typeToBG(theme: DefaultTheme): Record {
}
}
-function typeToHoverBG(theme: DefaultTheme): Record {
+function typeToHoverBG(theme: DefaultTheme): Record {
return {
secondary: theme.colors['action-input-hover'],
tertiary: theme.colors['action-input-hover'],
@@ -37,7 +37,9 @@ function typeToHoverBG(theme: DefaultTheme): Record {
}
}
-function typeToSelectedBG(theme: DefaultTheme): Record {
+function typeToSelectedBG(
+ theme: DefaultTheme
+): Record {
return {
secondary: undefined,
tertiary: undefined,
@@ -48,7 +50,7 @@ function typeToSelectedBG(theme: DefaultTheme): Record {
}
}
-function typeToFocusBG(theme: DefaultTheme): Record {
+function typeToFocusBG(theme: DefaultTheme): Record {
return {
secondary: undefined,
tertiary: undefined,
diff --git a/assets/design-system/src/components/Input2.tsx b/assets/design-system/src/components/Input2.tsx
index e9aae3822d..d06895c7e3 100644
--- a/assets/design-system/src/components/Input2.tsx
+++ b/assets/design-system/src/components/Input2.tsx
@@ -211,13 +211,13 @@ const InputAreaSC = styled.div((_) => ({
flex: '1 1',
overflowX: 'auto',
}))
-const InputContentSC = styled.div<{ $padStart: keyof DefaultTheme['spacing'] }>(
- ({ theme, $padStart }) => ({
- display: 'flex',
- alignSelf: 'stretch',
- paddingLeft: theme.spacing[$padStart],
- })
-)
+const InputContentSC = styled.div<{
+ $padStart?: keyof DefaultTheme['spacing'] | null
+}>(({ theme, $padStart }) => ({
+ display: 'flex',
+ alignSelf: 'stretch',
+ ...($padStart ? { paddingLeft: theme.spacing[$padStart] } : {}),
+}))
function Input2({
ref,
@@ -266,7 +266,7 @@ function Input2({
(inputAreaRef.current?.getBoundingClientRect().width ?? 0)
if (scrollDiff > 0) {
- inputAreaRef.current.scrollTo({
+ inputAreaRef.current?.scrollTo({
left: scrollDiff + 1,
behavior: 'smooth',
})
@@ -293,33 +293,37 @@ function Input2({
const inputPadStart = startIcon ? null : hasStartContent ? 'small' : 'medium'
const inputPadEnd = endIcon ? null : hasEndContent ? 'small' : 'medium'
- const wrappedOnChange: InputPropsFull['onChange'] = useCallback(
+ const wrappedOnChange: NonNullable = useCallback(
(e) => {
onChange?.(e)
},
[onChange]
)
- const wrappedOnKeyDown: InputPropsFull['onKeyDown'] = useCallback(
+ const wrappedOnKeyDown: NonNullable =
+ useCallback(
+ (e) => {
+ if (e.key === 'Enter' && typeof onEnter === 'function') {
+ onEnter?.(e)
+ }
+ if (e.key === 'Backspace' && inputRef?.current?.selectionStart === 0) {
+ onDeleteInputContent?.(e)
+ }
+ if (typeof onKeyDown === 'function') {
+ onKeyDown?.(e)
+ }
+ },
+ [onDeleteInputContent, onEnter, onKeyDown]
+ )
+
+ const outerOnClick: NonNullable = useCallback(
(e) => {
- if (e.key === 'Enter' && typeof onEnter === 'function') {
- onEnter?.(e)
- }
- if (e.key === 'Backspace' && inputRef?.current?.selectionStart === 0) {
- onDeleteInputContent?.(e)
- }
- if (typeof onKeyDown === 'function') {
- onKeyDown?.(e)
- }
+ e.preventDefault()
+ inputRef?.current?.focus()
},
- [onDeleteInputContent, onEnter, onKeyDown]
+ []
)
- const outerOnClick: InputPropsFull['onClick'] = useCallback((e) => {
- e.preventDefault()
- inputRef?.current?.focus()
- }, [])
-
return (
& {
- selectedKey: Key
+ selectedKey?: Key | null
onSelectionChange: (key: Key) => unknown
onHeaderClick?: () => unknown
onFooterClick?: () => unknown
@@ -109,7 +109,8 @@ function propsToTextValue(props: Record | null | undefined) {
}
function useItemWrappedChildren(
- children: ReactElement | (ReactElement | false)[],
+ children?:
+ ReactElement | (ReactElement | false | null | undefined)[] | null,
header?: ReactElement,
footer?: ReactElement
) {
@@ -238,11 +239,8 @@ function ListBoxUnmanaged({
const theme = useTheme()
// Get props for the listbox element
- let ref = useRef(undefined)
-
- if (listBoxRef) {
- ref = listBoxRef
- }
+ const fallbackRef = useRef(null)
+ const ref = listBoxRef ?? fallbackRef
const { listBoxProps } = useListBox(props, state, ref)
return (
@@ -253,7 +251,7 @@ function ListBoxUnmanaged({
>
{headerFixed && {headerFixed}
}
}
extendStyle={{
paddingTop: headerFixed ? 0 : theme.spacing.xxxsmall,
paddingBottom: footerFixed ? 0 : theme.spacing.xxxsmall,
@@ -275,7 +273,7 @@ function ListBoxUnmanaged({
function Option({ item, state }: { item: any; state: ListState