From 88f245d476a6477e9fc0cd35e9b675961ecbc26c Mon Sep 17 00:00:00 2001 From: Jozen Blue Martinez Date: Sun, 11 Dec 2022 23:10:01 +0800 Subject: [PATCH] feat(DialogCheckbox): Add DialogCheckbox component (#58) * feat(DialogCheckbox): Add DialogCheckbox component * fix(DialogCheckbox): Better sibling match * fix(DialogCheckbox): Extend FocusableProps * fix(DialogCheckbox): Extend FooterLegendProps i should have probably tested that * feat(DialogCheckbox): add onClick() prop * fix(DialogCheckbox): replace default export with named export --- src/deck-components/DialogCheckbox.tsx | 33 ++++++++++++++++++++++++++ src/deck-components/index.ts | 1 + 2 files changed, 34 insertions(+) create mode 100644 src/deck-components/DialogCheckbox.tsx diff --git a/src/deck-components/DialogCheckbox.tsx b/src/deck-components/DialogCheckbox.tsx new file mode 100644 index 0000000..b16068d --- /dev/null +++ b/src/deck-components/DialogCheckbox.tsx @@ -0,0 +1,33 @@ +import { FC, ReactNode } from 'react'; + +import { findModule } from '../webpack'; +import { DialogCommonProps } from './Dialog'; +import { FooterLegendProps } from './FooterLegend'; + +export interface DialogCheckboxProps extends DialogCommonProps, FooterLegendProps { + onChange?(checked: boolean): void; + label?: ReactNode; + description?: ReactNode; + disabled?: boolean; + tooltip?: string; + color?: string; + highlightColor?: string; + bottomSeparator?: 'standard' | 'thick' | 'none'; + controlled?: boolean; + checked?: boolean; + onClick?(evt: Event): void; +} + +export const DialogCheckbox = Object.values(findModule((m: any) => { + if (typeof m !== 'object') return false; + for (const prop in m) { + if (m[prop]?.prototype?.GetPanelElementProps) return true; + } + return false; +})).find((m: any) => + m.contextType && + m.prototype?.render.toString().includes('fallback:') && + m?.prototype?.SetChecked && + m?.prototype?.Toggle && + m?.prototype?.GetPanelElementProps +) as FC; diff --git a/src/deck-components/index.ts b/src/deck-components/index.ts index 3bb96c3..d235e0f 100755 --- a/src/deck-components/index.ts +++ b/src/deck-components/index.ts @@ -3,6 +3,7 @@ export * from './ButtonItem'; export * from './Carousel'; export * from './ControlsList'; export * from './Dialog'; +export * from './DialogCheckbox'; export * from './Dropdown'; export * from './Field'; export * from './Focusable';