@plasmicpkgs/plasmic-tabs 0.0.6 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,7 +25,9 @@ function _extends() {
25
25
  return _extends.apply(this, arguments);
26
26
  }
27
27
 
28
- var noop = function noop() {};
28
+ var noop = function noop() {
29
+ // noop
30
+ };
29
31
  function defaultButtonChildren(label) {
30
32
  return {
31
33
  type: 'default-component',
@@ -40,7 +42,9 @@ function defaultButtonChildren(label) {
40
42
  }
41
43
  var DebugContext = /*#__PURE__*/React.createContext(false);
42
44
  function useTabsData(_ref) {
43
- var initialKey = _ref.initialKey;
45
+ var initialKey = _ref.initialKey,
46
+ _ref$mountMode = _ref.mountMode,
47
+ mountMode = _ref$mountMode === void 0 ? 'mountOneAtATime' : _ref$mountMode;
44
48
  var _useState = React.useState(initialKey),
45
49
  tabKey = _useState[0],
46
50
  setTabKey = _useState[1];
@@ -51,7 +55,8 @@ function useTabsData(_ref) {
51
55
  tabKey: tabKey,
52
56
  bbox: bbox,
53
57
  setTabKey: setTabKey,
54
- setBbox: setBbox
58
+ setBbox: setBbox,
59
+ mountMode: mountMode
55
60
  };
56
61
  }
57
62
  var _constate = /*#__PURE__*/constate(useTabsData),
@@ -86,6 +91,22 @@ var TabsContainerMeta = {
86
91
  type: 'boolean',
87
92
  description: 'Reveal all tab contents while editing in Plasmic Studio'
88
93
  },
94
+ mountMode: {
95
+ advanced: true,
96
+ description: 'How to render/mount tab content.',
97
+ type: 'choice',
98
+ options: [{
99
+ label: 'Mount one at a time, unmount on hide',
100
+ value: 'mountOneAtATime'
101
+ }, {
102
+ label: 'Mount all up-front, do not unmount',
103
+ value: 'mountAllEagerly'
104
+ }, {
105
+ label: 'Mount on-demand/lazily, do not unmount',
106
+ value: 'mountLazily'
107
+ }],
108
+ defaultValueHint: 'mountOneAtATime'
109
+ },
89
110
  children: {
90
111
  type: 'slot',
91
112
  defaultValue: {
@@ -278,14 +299,40 @@ var TabContentMeta = {
278
299
  };
279
300
  function TabContent(_ref8) {
280
301
  var children = _ref8.children,
302
+ className = _ref8.className,
281
303
  tabKey = _ref8.tabKey;
282
304
  var tabsContext = useTabsContext();
283
305
  var previewAll = React.useContext(DebugContext);
284
306
  var _ref9 = tabsContext != null ? tabsContext : {
285
- tabKey: undefined
307
+ tabKey: undefined,
308
+ mountMode: 'mountOneAtATime'
286
309
  },
287
- activeKey = _ref9.tabKey;
288
- return React__default.createElement(React__default.Fragment, null, tabsContext === undefined || activeKey === tabKey || previewAll ? children : null);
310
+ activeKey = _ref9.tabKey,
311
+ mountMode = _ref9.mountMode;
312
+ var show = tabsContext === undefined || activeKey === tabKey || previewAll;
313
+ var _useState3 = React.useState(false),
314
+ everMounted = _useState3[0],
315
+ setEverMounted = _useState3[1];
316
+ React.useEffect(function () {
317
+ if (show) {
318
+ setEverMounted(true);
319
+ }
320
+ }, [show]);
321
+ var divContent = React__default.createElement("div", {
322
+ className: className,
323
+ style: show ? {} : {
324
+ display: 'none'
325
+ }
326
+ }, children);
327
+ switch (mountMode) {
328
+ case 'mountOneAtATime':
329
+ return React__default.createElement(React__default.Fragment, null, show ? children : null);
330
+ case 'mountAllEagerly':
331
+ return divContent;
332
+ case 'mountLazily':
333
+ return React__default.createElement(React__default.Fragment, null, everMounted && divContent);
334
+ }
335
+ throw new Error("Unexpected mount mode " + mountMode);
289
336
  }
290
337
 
291
338
  function registerAll(loader) {
@@ -1 +1 @@
1
- {"version":3,"file":"plasmic-tabs.cjs.development.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nfunction useTabsData({ initialKey }: { initialKey?: string }) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n importPath: modulePath,\n providesData: true,\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'SShow this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={'currentTabKey'} data={effectiveKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const { tabKey: activeKey, setTabKey, bbox, setBbox } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\nexport function TabContent({ children, tabKey }: TabContentProps) {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey } = tabsContext ?? { tabKey: undefined };\n return (\n <>\n {tabsContext === undefined || activeKey === tabKey || previewAll\n ? children\n : null}\n </>\n );\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","initialKey","useState","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","TabsContainer","inEditor","usePlasmicCanvasContext","React","Provider","Helper","ensure","x","Error","effectiveKey","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,IAAI,GAAG,SAAPA,IAAI,KAAW;AAErB,SAASC,qBAAqB,CAACC,KAAa;EAC1C,OAAO;IACLC,IAAI,EAAE,mBAAmB;IACzBC,IAAI,EAAE,QAAQ;IACdC,KAAK,EAAE;MACLC,QAAQ,EAAE;QACRH,IAAI,EAAE,MAAM;QACZI,KAAK,EAAEL;;;GAGH;AACZ;AAQA,IAAMM,YAAY,gBAAGC,mBAAa,CAAC,KAAK,CAAC;AAEzC,SAASC,WAAW;MAAGC,UAAU,QAAVA,UAAU;EAC/B,gBAA4BC,cAAQ,CAAqBD,UAAU,CAAC;IAA7DE,MAAM;IAAEC,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mic-tabs.cjs.development.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {\n // noop\n};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nexport type MountMode = 'mountOneAtATime' | 'mountAllEagerly' | 'mountLazily';\n\nfunction useTabsData({\n initialKey,\n mountMode = 'mountOneAtATime',\n}: {\n initialKey?: string;\n mountMode?: MountMode;\n}) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\n mountMode,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n importPath: modulePath,\n providesData: true,\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'SShow this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n mountMode: {\n advanced: true,\n description: 'How to render/mount tab content.',\n type: 'choice',\n options: [\n {\n label: 'Mount one at a time, unmount on hide',\n value: 'mountOneAtATime',\n },\n {\n label: 'Mount all up-front, do not unmount',\n value: 'mountAllEagerly',\n },\n {\n label: 'Mount on-demand/lazily, do not unmount',\n value: 'mountLazily',\n },\n ],\n defaultValueHint: 'mountOneAtATime',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={'currentTabKey'} data={effectiveKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const {\n tabKey: activeKey,\n setTabKey,\n bbox,\n setBbox,\n } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n className?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\n\nexport function TabContent({\n children,\n className,\n tabKey,\n}: TabContentProps): ReactElement {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey, mountMode } = tabsContext ?? {\n tabKey: undefined,\n mountMode: 'mountOneAtATime',\n };\n const show = tabsContext === undefined || activeKey === tabKey || previewAll;\n const [everMounted, setEverMounted] = useState(false);\n useEffect(() => {\n if (show) {\n setEverMounted(true);\n }\n }, [show]);\n const divContent = (\n <div className={className} style={show ? {} : { display: 'none' }}>\n {children}\n </div>\n );\n switch (mountMode) {\n case 'mountOneAtATime':\n return <>{show ? children : null}</>;\n case 'mountAllEagerly':\n return divContent;\n case 'mountLazily':\n return <>{everMounted && divContent}</>;\n }\n throw new Error(`Unexpected mount mode ${mountMode}`);\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","initialKey","mountMode","useState","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","advanced","options","defaultValueHint","TabsContainer","inEditor","usePlasmicCanvasContext","React","Provider","Helper","ensure","x","Error","effectiveKey","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","show","everMounted","setEverMounted","divContent","display","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,IAAI,GAAG,SAAPA,IAAI;;AACR,CACD;AAED,SAASC,qBAAqB,CAACC,KAAa;EAC1C,OAAO;IACLC,IAAI,EAAE,mBAAmB;IACzBC,IAAI,EAAE,QAAQ;IACdC,KAAK,EAAE;MACLC,QAAQ,EAAE;QACRH,IAAI,EAAE,MAAM;QACZI,KAAK,EAAEL;;;GAGH;AACZ;AAQA,IAAMM,YAAY,gBAAGC,mBAAa,CAAC,KAAK,CAAC;AAIzC,SAASC,WAAW;MAClBC,UAAU,QAAVA,UAAU;IAAA,sBACVC,SAAS;IAATA,SAAS,+BAAG,iBAAiB;EAK7B,gBAA4BC,cAAQ,CAAqBF,UAAU,CAAC;IAA7DG,MAAM;IAAEC,SAAS;EACxB,iBAAwBF,cAAQ,CAC9BG,SAAS,CACV;IAFMC,IAAI;IAAEC,OAAO;EAGpB,OAAO;IACLJ,MAAM,EAANA,MAAM;IACNG,IAAI,EAAJA,IAAI;IACJF,SAAS,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GAAG,EAAE,GAAG;MAAEI,OAAO,EAAE;;KACtDpF,QAAQ,CAEZ;EACD,QAAQM,SAAS;IACf,KAAK,iBAAiB;MACpB,OAAOgC,4DAAG0C,IAAI,GAAGhF,QAAQ,GAAG,IAAI,CAAI;IACtC,KAAK,iBAAiB;MACpB,OAAOmF,UAAU;IACnB,KAAK,aAAa;MAChB,OAAO7C,4DAAG2C,WAAW,IAAIE,UAAU,CAAI;;EAE3C,MAAM,IAAIxC,KAAK,4BAA0BrC,SAAS,CAAG;AACvD;;SC5WgB+E,WAAW,CAACC,MAE3B;EACC,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkB,CACtBC,SAAY,EACZC,WAAmD;IAEnD,IAAIH,MAAM,EAAE;MACVA,MAAM,CAACI,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;KACjD,MAAM;MACLC,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;;GAE5C;EAEDF,kBAAkB,CAACpD,aAAa,EAAEhB,iBAAiB,CAAC;EACpDoE,kBAAkB,CAACrC,YAAY,EAAEH,gBAAgB,CAAC;EAClDwC,kBAAkB,CAACzB,SAAS,EAAEF,aAAa,CAAC;EAC5C2B,kBAAkB,CAACT,UAAU,EAAED,cAAc,CAAC;AAEhD;;;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("@plasmicapp/host/registerComponent")),n=require("@plasmicapp/host"),a=e(require("constate")),r=require("react"),i=e(r);function o(){return(o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}var s=function(){};function l(e){return{type:"default-component",kind:"button",props:{children:{type:"text",value:e}}}}var p=r.createContext(!1);function c(e){var t=r.useState(e.initialKey),n=t[0],a=t[1],i=r.useState(void 0);return{tabKey:n,bbox:i[0],setTabKey:a,setBbox:i[1]}}var b=a(c),u=b[0],d=b[1];function y(){var e=d();return"setTabKey"in e?e:void 0}var m="@plasmicpkgs/plasmic-tabs",h={name:"hostless-tabs-container",displayName:"Tabs Container",importName:"TabsContainer",importPath:m,providesData:!0,defaultStyles:{width:"stretch",padding:"8px"},props:{initialKey:{type:"string",description:"Key of the initially selected tab",defaultValue:"tab1"},previewKey:{type:"string",description:"SShow this key while editing in Plasmic Studio"},previewAll:{type:"boolean",description:"Reveal all tab contents while editing in Plasmic Studio"},children:{type:"slot",defaultValue:{type:"vbox",children:[{type:"hbox",children:[{type:"component",name:"hostless-tab-button",props:{tabKey:"tab1",children:l("Tab 1")}},{type:"component",name:"hostless-tab-button",props:{tabKey:"tab2",children:l("Tab 2")}},{type:"component",name:"hostless-tab-underline"}]},{type:"vbox",children:[{type:"component",name:"hostless-tab-content",props:{tabKey:"tab1",children:[{type:"vbox",children:["Some content for tab 1"]}]}},{type:"component",name:"hostless-tab-content",props:{tabKey:"tab2",children:[{type:"vbox",children:["Some content for tab 2"]}]}}]}]}}}};function v(e){var t=e.children,a=e.initialKey,r=e.previewKey,o=e.previewAll,s=void 0!==o&&o,l=!!n.usePlasmicCanvasContext();return i.createElement(u,{initialKey:a},i.createElement(p.Provider,{value:l&&s},i.createElement(f,{previewKey:r||a},t)))}function f(e){var t=e.children,a=e.previewKey,r=n.usePlasmicCanvasContext(),o=function(e){if(!e)throw new Error("unexpected nil");return e}(y()).tabKey;return i.createElement(n.DataProvider,{name:"currentTabKey",data:r&&a||o},t)}var x={name:"hostless-tab-underline",displayName:"Tab Underline",importName:"TabUnderline",importPath:m,props:{},defaultStyles:{background:"#7777ff",height:"2px"}};function K(e){var t,n=e.className,a=(null!=(t=y())?t:{bbox:void 0}).bbox;return a?i.createElement("div",{className:n,style:o({},JSON.parse(JSON.stringify(a)),{top:void 0,bottom:0,position:"absolute",transition:".4s ease all"})}):null}var T={name:"hostless-tab-button",isAttachment:!0,displayName:"Tab Button",importName:"TabButton",importPath:m,props:{tabKey:{type:"string",description:"The answer value selecting this choice sets"},children:{type:"slot",defaultValue:l("Some tab")}},defaultStyles:{width:"hug"}};function g(e){var t=e.className,n=e.children,a=e.tabKey,o=y(),l=r.useRef(null),p=null!=o?o:{tabKey:void 0,setTabKey:s,bbox:void 0,setBbox:s},c=p.tabKey,b=p.setTabKey,u=p.setBbox;return r.useEffect((function(){a===c&&u({width:l.current.offsetWidth,left:l.current.offsetLeft})}),[l.current,u,JSON.stringify(p.bbox),a,c]),i.createElement("div",{className:t,ref:l},r.cloneElement(i.Children.toArray(n)[0],{isActive:a&&c&&c===a,onClick:function(){b(a)}}))}var C={name:"hostless-tab-content",isAttachment:!0,displayName:"Tab Content",importName:"TabContent",importPath:m,props:{tabKey:{type:"string",description:"The answer value selecting this choice sets"},children:{type:"slot",defaultValue:{type:"vbox",children:{type:"text",value:"This is some tab content"}}}}};function w(e){var t=e.children,n=e.tabKey,a=y(),o=r.useContext(p);return i.createElement(i.Fragment,null,void 0===a||(null!=a?a:{tabKey:void 0}).tabKey===n||o?t:null)}exports.TabButton=g,exports.TabButtonMeta=T,exports.TabContent=w,exports.TabContentMeta=C,exports.TabUnderline=K,exports.TabUnderlineMeta=x,exports.TabsContainer=v,exports.TabsContainerMeta=h,exports.registerAll=function(e){var n=function(n,a){e?e.registerComponent(n,a):t(n,a)};n(v,h),n(K,x),n(g,T),n(w,C)};
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("@plasmicapp/host/registerComponent")),n=require("@plasmicapp/host"),a=e(require("constate")),o=require("react"),r=e(o);function i(){return(i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e}).apply(this,arguments)}var s=function(){};function l(e){return{type:"default-component",kind:"button",props:{children:{type:"text",value:e}}}}var u=o.createContext(!1);function c(e){var t=e.mountMode,n=void 0===t?"mountOneAtATime":t,a=o.useState(e.initialKey),r=a[0],i=a[1],s=o.useState(void 0);return{tabKey:r,bbox:s[0],setTabKey:i,setBbox:s[1],mountMode:n}}var p=a(c),d=p[0],b=p[1];function m(){var e=b();return"setTabKey"in e?e:void 0}var y="@plasmicpkgs/plasmic-tabs",h={name:"hostless-tabs-container",displayName:"Tabs Container",importName:"TabsContainer",importPath:y,providesData:!0,defaultStyles:{width:"stretch",padding:"8px"},props:{initialKey:{type:"string",description:"Key of the initially selected tab",defaultValue:"tab1"},previewKey:{type:"string",description:"SShow this key while editing in Plasmic Studio"},previewAll:{type:"boolean",description:"Reveal all tab contents while editing in Plasmic Studio"},mountMode:{advanced:!0,description:"How to render/mount tab content.",type:"choice",options:[{label:"Mount one at a time, unmount on hide",value:"mountOneAtATime"},{label:"Mount all up-front, do not unmount",value:"mountAllEagerly"},{label:"Mount on-demand/lazily, do not unmount",value:"mountLazily"}],defaultValueHint:"mountOneAtATime"},children:{type:"slot",defaultValue:{type:"vbox",children:[{type:"hbox",children:[{type:"component",name:"hostless-tab-button",props:{tabKey:"tab1",children:l("Tab 1")}},{type:"component",name:"hostless-tab-button",props:{tabKey:"tab2",children:l("Tab 2")}},{type:"component",name:"hostless-tab-underline"}]},{type:"vbox",children:[{type:"component",name:"hostless-tab-content",props:{tabKey:"tab1",children:[{type:"vbox",children:["Some content for tab 1"]}]}},{type:"component",name:"hostless-tab-content",props:{tabKey:"tab2",children:[{type:"vbox",children:["Some content for tab 2"]}]}}]}]}}}};function v(e){var t=e.children,a=e.initialKey,o=e.previewKey,i=e.previewAll,s=void 0!==i&&i,l=!!n.usePlasmicCanvasContext();return r.createElement(d,{initialKey:a},r.createElement(u.Provider,{value:l&&s},r.createElement(f,{previewKey:o||a},t)))}function f(e){var t=e.children,a=e.previewKey,o=n.usePlasmicCanvasContext(),i=function(e){if(!e)throw new Error("unexpected nil");return e}(m()).tabKey;return r.createElement(n.DataProvider,{name:"currentTabKey",data:o&&a||i},t)}var x={name:"hostless-tab-underline",displayName:"Tab Underline",importName:"TabUnderline",importPath:y,props:{},defaultStyles:{background:"#7777ff",height:"2px"}};function T(e){var t,n=e.className,a=(null!=(t=m())?t:{bbox:void 0}).bbox;return a?r.createElement("div",{className:n,style:i({},JSON.parse(JSON.stringify(a)),{top:void 0,bottom:0,position:"absolute",transition:".4s ease all"})}):null}var K={name:"hostless-tab-button",isAttachment:!0,displayName:"Tab Button",importName:"TabButton",importPath:y,props:{tabKey:{type:"string",description:"The answer value selecting this choice sets"},children:{type:"slot",defaultValue:l("Some tab")}},defaultStyles:{width:"hug"}};function g(e){var t=e.className,n=e.children,a=e.tabKey,i=m(),l=o.useRef(null),u=null!=i?i:{tabKey:void 0,setTabKey:s,bbox:void 0,setBbox:s},c=u.tabKey,p=u.setTabKey,d=u.setBbox;return o.useEffect((function(){a===c&&d({width:l.current.offsetWidth,left:l.current.offsetLeft})}),[l.current,d,JSON.stringify(u.bbox),a,c]),r.createElement("div",{className:t,ref:l},o.cloneElement(r.Children.toArray(n)[0],{isActive:a&&c&&c===a,onClick:function(){p(a)}}))}var w={name:"hostless-tab-content",isAttachment:!0,displayName:"Tab Content",importName:"TabContent",importPath:y,props:{tabKey:{type:"string",description:"The answer value selecting this choice sets"},children:{type:"slot",defaultValue:{type:"vbox",children:{type:"text",value:"This is some tab content"}}}}};function A(e){var t=e.children,n=e.className,a=e.tabKey,i=m(),s=o.useContext(u),l=null!=i?i:{tabKey:void 0,mountMode:"mountOneAtATime"},c=l.mountMode,p=void 0===i||l.tabKey===a||s,d=o.useState(!1),b=d[0],y=d[1];o.useEffect((function(){p&&y(!0)}),[p]);var h=r.createElement("div",{className:n,style:p?{}:{display:"none"}},t);switch(c){case"mountOneAtATime":return r.createElement(r.Fragment,null,p?t:null);case"mountAllEagerly":return h;case"mountLazily":return r.createElement(r.Fragment,null,b&&h)}throw new Error("Unexpected mount mode "+c)}exports.TabButton=g,exports.TabButtonMeta=K,exports.TabContent=A,exports.TabContentMeta=w,exports.TabUnderline=T,exports.TabUnderlineMeta=x,exports.TabsContainer=v,exports.TabsContainerMeta=h,exports.registerAll=function(e){var n=function(n,a){e?e.registerComponent(n,a):t(n,a)};n(v,h),n(T,x),n(g,K),n(A,w)};
2
2
  //# sourceMappingURL=plasmic-tabs.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plasmic-tabs.cjs.production.min.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nfunction useTabsData({ initialKey }: { initialKey?: string }) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n importPath: modulePath,\n providesData: true,\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'SShow this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={'currentTabKey'} data={effectiveKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const { tabKey: activeKey, setTabKey, bbox, setBbox } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\nexport function TabContent({ children, tabKey }: TabContentProps) {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey } = tabsContext ?? { tabKey: undefined };\n return (\n <>\n {tabsContext === undefined || activeKey === tabKey || previewAll\n ? children\n : null}\n </>\n );\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","useState","initialKey","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","TabsContainer","_ref2$previewAll","inEditor","usePlasmicCanvasContext","React","Provider","Helper","x","Error","ensure","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":"qfAiBA,IAAMA,EAAO,aAEb,SAASC,EAAsBC,GAC7B,MAAO,CACLC,KAAM,oBACNC,KAAM,SACNC,MAAO,CACLC,SAAU,CACRH,KAAM,OACNI,MAAOL,KAYf,IAAMM,EAAeC,iBAAc,GAEnC,SAASC,WACqBC,aADPC,YACdC,OAAQC,SACSH,gBACtBI,GAEF,MAAO,CACLF,OAAAA,EACAG,UACAF,UAAAA,EACAG,cAIJ,MAA6CC,EAASR,GAA/CS,OAAcC,OAErB,SAASC,IACP,IAAMC,EAASF,IACf,MAAO,cAAeE,EAASA,OAASP,EAE1C,IAAMQ,EAAa,4BAENC,EAAsD,CACjEC,KAAM,0BACNC,YAAa,iBACbC,WAAY,gBACZC,WAAYL,EACZM,cAAc,EACdC,cAAe,CACbC,MAAO,UACPC,QAAS,OAEX3B,MAAO,CACLO,WAAY,CACVT,KAAM,SACN8B,YAAa,oCACbC,aAAc,QAEhBC,WAAY,CACVhC,KAAM,SACN8B,YAAa,kDAEfG,WAAY,CACVjC,KAAM,UACN8B,YAAa,2DAEf3B,SAAU,CACRH,KAAM,OACN+B,aAAc,CACZ/B,KAAM,OACNG,SAAU,CACR,CACEH,KAAM,OACNG,SAAU,CACR,CACEH,KAAM,YACNsB,KAAM,sBACNpB,MAAO,CACLQ,OAAQ,OACRP,SAAUL,EAAsB,WAGpC,CACEE,KAAM,YACNsB,KAAM,sBACNpB,MAAO,CACLQ,OAAQ,OACRP,SAAUL,EAAsB,WAGpC,CACEE,KAAM,YACNsB,KAAM,4BAIZ,CACEtB,KAAM,OACNG,SAAU,CACR,CACEH,KAAM,YACNsB,KAAM,uBACNpB,MAAO,CACLQ,OAAQ,OACRP,SAAU,CACR,CACEH,KAAM,OACNG,SAAU,CAAC,8BAKnB,CACEH,KAAM,YACNsB,KAAM,uBACNp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KoE,IAARvD,OAAmBC,IAAAA,UAAiBG,IAAAA,QAc5C,OARAoD,aAAU,WACJxD,IAAWuD,GACbnD,EAAQ,CACNc,MAAOmC,EAAII,QAASC,YACpBC,KAAMN,EAAII,QAASG,eAGtB,CAACP,EAAII,QAASrD,EAASsC,KAAKE,YAbOzC,MAaUH,EAAQuD,IAEtD3B,uBAAKY,UAAWA,EAAWa,IAAKA,GAC7BQ,eAAajC,EAAMkC,SAASC,QAAQtE,GAAU,GAAoB,CACjEuE,SAAUhE,GAAUuD,GAAaA,IAAcvD,EAC/CiE,QAAS,WACPhE,EAAUD,WAYPkE,EAAiD,CAC5DtD,KAAM,uBACNsC,cAAc,EACdrC,YAAa,cACbC,WAAY,aACZC,WAAYL,EACZlB,MAAO,CACLQ,OAAQ,CACNV,KAAM,SACN8B,YAAa,+CAEf3B,SAAU,CACRH,KAAM,OACN+B,aAAc,CACZ/B,KAAM,OACNG,SAAU,CACRH,KAAM,OACNI,MAAO,yCAMDyE,SAAa1E,IAAAA,SAAUO,IAAAA,OAC/BoD,EAAc5C,IACde,EAAa6C,aAAWzE,GAE9B,OACEiC,qCACmB1B,IAAhBkD,UAHyBA,EAAAA,EAAe,CAAEpD,YAAQE,IAA/CF,SAGwCA,GAAUuB,EAClD9B,EACA,mOC9SkB4E,GAG1B,IAAMC,EAAqB,SACzBC,EACAC,GAEIH,EACFA,EAAOI,kBAAkBF,EAAWC,GAEpCC,EAAkBF,EAAWC,IAIjCF,EAAmB9C,EAAeb,GAClC2D,EAAmB/B,EAAcH,GACjCkC,EAAmBnB,EAAWF,GAC9BqB,EAAmBH,EAAYD"}
1
+ {"version":3,"file":"plasmic-tabs.cjs.production.min.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {\n // noop\n};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nexport type MountMode = 'mountOneAtATime' | 'mountAllEagerly' | 'mountLazily';\n\nfunction useTabsData({\n initialKey,\n mountMode = 'mountOneAtATime',\n}: {\n initialKey?: string;\n mountMode?: MountMode;\n}) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\n mountMode,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n importPath: modulePath,\n providesData: true,\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'SShow this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n mountMode: {\n advanced: true,\n description: 'How to render/mount tab content.',\n type: 'choice',\n options: [\n {\n label: 'Mount one at a time, unmount on hide',\n value: 'mountOneAtATime',\n },\n {\n label: 'Mount all up-front, do not unmount',\n value: 'mountAllEagerly',\n },\n {\n label: 'Mount on-demand/lazily, do not unmount',\n value: 'mountLazily',\n },\n ],\n defaultValueHint: 'mountOneAtATime',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={'currentTabKey'} data={effectiveKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const {\n tabKey: activeKey,\n setTabKey,\n bbox,\n setBbox,\n } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n className?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\n\nexport function TabContent({\n children,\n className,\n tabKey,\n}: TabContentProps): ReactElement {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey, mountMode } = tabsContext ?? {\n tabKey: undefined,\n mountMode: 'mountOneAtATime',\n };\n const show = tabsContext === undefined || activeKey === tabKey || previewAll;\n const [everMounted, setEverMounted] = useState(false);\n useEffect(() => {\n if (show) {\n setEverMounted(true);\n }\n }, [show]);\n const divContent = (\n <div className={className} style={show ? {} : { display: 'none' }}>\n {children}\n </div>\n );\n switch (mountMode) {\n case 'mountOneAtATime':\n return <>{show ? children : null}</>;\n case 'mountAllEagerly':\n return divContent;\n case 'mountLazily':\n return <>{everMounted && divContent}</>;\n }\n throw new Error(`Unexpected mount mode ${mountMode}`);\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","_ref$mountMode","mountMode","useState","initialKey","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","advanced","options","defaultValueHint","TabsContainer","_ref2$previewAll","inEditor","usePlasmicCanvasContext","React","Provider","Helper","x","Error","ensure","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","show","everMounted","setEverMounted","divContent","display","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":"qfAiBA,IAAMA,EAAO,aAIb,SAASC,EAAsBC,GAC7B,MAAO,CACLC,KAAM,oBACNC,KAAM,SACNC,MAAO,CACLC,SAAU,CACRH,KAAM,OACNI,MAAOL,KAYf,IAAMM,EAAeC,iBAAc,GAInC,SAASC,SACGC,IACVC,UAAAA,aAAY,sBAKgBC,aAN5BC,YAMOC,OAAQC,SACSH,gBACtBI,GAEF,MAAO,CACLF,OAAAA,EACAG,UACAF,UAAAA,EACAG,aACAP,UAAAA,GAIJ,MAA6CQ,EAASV,GAA/CW,OAAcC,OAErB,SAASC,IACP,IAAMC,EAASF,IACf,MAAO,cAAeE,EAASA,OAASP,EAE1C,IAAMQ,EAAa,4BAENC,EAAsD,CACjEC,KAAM,0BACNC,YAAa,iBACbC,WAAY,gBACZC,WAAYL,EACZM,cAAc,EACdC,cAAe,CACbC,MAAO,UACPC,QAAS,OAEX7B,MAAO,CACLS,WAAY,CACVX,KAAM,SACNgC,YAAa,oCACbC,aAAc,QAEhBC,WAAY,CACVlC,KAAM,SACNgC,YAAa,kDAEfG,WAAY,CACVnC,KAAM,UACNgC,YAAa,2DAEfvB,UAAW,CACT2B,UAAU,EACVJ,YAAa,mCACbhC,KAAM,SACNqC,QAAS,CACP,CACEtC,MAAO,uCACPK,MAAO,mBAET,CACEL,MAAO,qCACPK,MAAO,mBAET,CACEL,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AAQE,EACRL,UAAW,mBAFcA,IAAAA,UAIrB2E,OAAuBtE,IAAhBqD,KAJLvD,SAIgDA,GAAUuB,IAC5BzB,YAAS,GAAxC2E,OAAaC,OACpBf,aAAU,WACJa,GACFE,GAAe,KAEhB,CAACF,IACJ,IAAMG,EACJ5C,uBAAKY,UAAWA,EAAWC,MAAO4B,EAAO,GAAK,CAAEI,QAAS,SACtDrF,GAGL,OAAQM,GACN,IAAK,kBACH,OAAOkC,gCAAGyC,EAAOjF,EAAW,MAC9B,IAAK,kBACH,OAAOoF,EACT,IAAK,cACH,OAAO5C,gCAAG0C,GAAeE,GAE7B,MAAM,IAAIxC,+BAA+BtC,gOC3WfgF,GAG1B,IAAMC,EAAqB,SACzBC,EACAC,GAEIH,EACFA,EAAOI,kBAAkBF,EAAWC,GAEpCC,EAAkBF,EAAWC,IAIjCF,EAAmBnD,EAAehB,GAClCmE,EAAmBpC,EAAcH,GACjCuC,EAAmBxB,EAAWF,GAC9B0B,EAAmBR,EAAYD"}
@@ -1,7 +1,7 @@
1
1
  import registerComponent from '@plasmicapp/host/registerComponent';
2
2
  import { usePlasmicCanvasContext, DataProvider } from '@plasmicapp/host';
3
3
  import constate from 'constate';
4
- import React, { useRef, useEffect, cloneElement, useContext, createContext, useState } from 'react';
4
+ import React, { useRef, useEffect, cloneElement, useContext, useState, createContext } from 'react';
5
5
 
6
6
  function _extends() {
7
7
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -18,7 +18,9 @@ function _extends() {
18
18
  return _extends.apply(this, arguments);
19
19
  }
20
20
 
21
- var noop = function noop() {};
21
+ var noop = function noop() {
22
+ // noop
23
+ };
22
24
  function defaultButtonChildren(label) {
23
25
  return {
24
26
  type: 'default-component',
@@ -33,7 +35,9 @@ function defaultButtonChildren(label) {
33
35
  }
34
36
  var DebugContext = /*#__PURE__*/createContext(false);
35
37
  function useTabsData(_ref) {
36
- var initialKey = _ref.initialKey;
38
+ var initialKey = _ref.initialKey,
39
+ _ref$mountMode = _ref.mountMode,
40
+ mountMode = _ref$mountMode === void 0 ? 'mountOneAtATime' : _ref$mountMode;
37
41
  var _useState = useState(initialKey),
38
42
  tabKey = _useState[0],
39
43
  setTabKey = _useState[1];
@@ -44,7 +48,8 @@ function useTabsData(_ref) {
44
48
  tabKey: tabKey,
45
49
  bbox: bbox,
46
50
  setTabKey: setTabKey,
47
- setBbox: setBbox
51
+ setBbox: setBbox,
52
+ mountMode: mountMode
48
53
  };
49
54
  }
50
55
  var _constate = /*#__PURE__*/constate(useTabsData),
@@ -79,6 +84,22 @@ var TabsContainerMeta = {
79
84
  type: 'boolean',
80
85
  description: 'Reveal all tab contents while editing in Plasmic Studio'
81
86
  },
87
+ mountMode: {
88
+ advanced: true,
89
+ description: 'How to render/mount tab content.',
90
+ type: 'choice',
91
+ options: [{
92
+ label: 'Mount one at a time, unmount on hide',
93
+ value: 'mountOneAtATime'
94
+ }, {
95
+ label: 'Mount all up-front, do not unmount',
96
+ value: 'mountAllEagerly'
97
+ }, {
98
+ label: 'Mount on-demand/lazily, do not unmount',
99
+ value: 'mountLazily'
100
+ }],
101
+ defaultValueHint: 'mountOneAtATime'
102
+ },
82
103
  children: {
83
104
  type: 'slot',
84
105
  defaultValue: {
@@ -271,14 +292,40 @@ var TabContentMeta = {
271
292
  };
272
293
  function TabContent(_ref8) {
273
294
  var children = _ref8.children,
295
+ className = _ref8.className,
274
296
  tabKey = _ref8.tabKey;
275
297
  var tabsContext = useTabsContext();
276
298
  var previewAll = useContext(DebugContext);
277
299
  var _ref9 = tabsContext != null ? tabsContext : {
278
- tabKey: undefined
300
+ tabKey: undefined,
301
+ mountMode: 'mountOneAtATime'
279
302
  },
280
- activeKey = _ref9.tabKey;
281
- return React.createElement(React.Fragment, null, tabsContext === undefined || activeKey === tabKey || previewAll ? children : null);
303
+ activeKey = _ref9.tabKey,
304
+ mountMode = _ref9.mountMode;
305
+ var show = tabsContext === undefined || activeKey === tabKey || previewAll;
306
+ var _useState3 = useState(false),
307
+ everMounted = _useState3[0],
308
+ setEverMounted = _useState3[1];
309
+ useEffect(function () {
310
+ if (show) {
311
+ setEverMounted(true);
312
+ }
313
+ }, [show]);
314
+ var divContent = React.createElement("div", {
315
+ className: className,
316
+ style: show ? {} : {
317
+ display: 'none'
318
+ }
319
+ }, children);
320
+ switch (mountMode) {
321
+ case 'mountOneAtATime':
322
+ return React.createElement(React.Fragment, null, show ? children : null);
323
+ case 'mountAllEagerly':
324
+ return divContent;
325
+ case 'mountLazily':
326
+ return React.createElement(React.Fragment, null, everMounted && divContent);
327
+ }
328
+ throw new Error("Unexpected mount mode " + mountMode);
282
329
  }
283
330
 
284
331
  function registerAll(loader) {
@@ -1 +1 @@
1
- {"version":3,"file":"plasmic-tabs.esm.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nfunction useTabsData({ initialKey }: { initialKey?: string }) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n importPath: modulePath,\n providesData: true,\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'SShow this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={'currentTabKey'} data={effectiveKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const { tabKey: activeKey, setTabKey, bbox, setBbox } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\nexport function TabContent({ children, tabKey }: TabContentProps) {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey } = tabsContext ?? { tabKey: undefined };\n return (\n <>\n {tabsContext === undefined || activeKey === tabKey || previewAll\n ? children\n : null}\n </>\n );\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","initialKey","useState","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","TabsContainer","inEditor","usePlasmicCanvasContext","React","Provider","Helper","ensure","x","Error","effectiveKey","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,IAAI,GAAG,SAAPA,IAAI,KAAW;AAErB,SAASC,qBAAqB,CAACC,KAAa;EAC1C,OAAO;IACLC,IAAI,EAAE,mBAAmB;IACzBC,IAAI,EAAE,QAAQ;IACdC,KAAK,EAAE;MACLC,QAAQ,EAAE;QACRH,IAAI,EAAE,MAAM;QACZI,KAAK,EAAEL;;;GAGH;AACZ;AAQA,IAAMM,YAAY,gBAAGC,aAAa,CAAC,KAAK,CAAC;AAEzC,SAASC,WAAW;MAAGC,UAAU,QAAVA,UAAU;EAC/B,gBAA4BC,QAAQ,CAAqBD,UAAU,CAAC;IAA7DE,MAAM;IAAEC,SAAS;EACxB,iBAAwBF,QAAQ,CAC9BG,SAAS,CACV;IAFMC,IAAI;IAAEC,OAAO;EAGpB,OAAO;IACLJ,MAAM,EAANA,MAAM;IACNG,IAAI,EAAJA,IAAI;IACJF,SAAS,EAATA,SAAS;IACTG,OAAO,EAAPA;GACD;AACH;AAEA,6BAA6CC,QAAQ,CAACR,WAAW,CAAC;EAA3DS,YAAY;EAAEC,oBAAoB;AAEzC,SAASC,cAAc;EACrB,IAAMC,MAAM,GAAGF,oBAAoB,EAAE;EACrC,OAAO,WAAW,IAAIE,MAAM,GAAGA,MAAM,GAAGP,SAAS;AACnD;AACA,IAAMQ,UAAU,GAAG,2BAA2B;IAEjCC,iBAAiB,GAAqC;EACjEC,IAAI,EAAE,yBAAyB;EAC/BC,WAAW,EAAE,gBA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,YAAY,CAAC;EAC3C,YAA8ByD,WAAW,WAAXA,WAAW,GAAI;MAAEpD,MAAM,EAAEE;KAAW;IAAlDqD,SAAS,SAAjBvD,MAAM;EACd,OACE2B,0CACGyB,WAAW,KAAKlD,SAAS,IAAIqD,SAAS,KAAKvD,MAAM,IAAIuB,UAAU,GAC5D9B,QAAQ,GACR,IAAI,CACP;AAEP;;SCjTgB4E,WAAW,CAACC,MAE3B;EACC,IAAMC,kBAAkB,GAAG,SAArBA,kBAAkB,CACtBC,SAAY,EACZC,WAAmD;IAEnD,IAAIH,MAAM,EAAE;MACVA,MAAM,CAACI,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;KACjD,MAAM;MACLC,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;;GAE5C;EAEDF,kBAAkB,CAAC/C,aAAa,EAAEb,iBAAiB,CAAC;EACpD4D,kBAAkB,CAAChC,YAAY,EAAEH,gBAAgB,CAAC;EAClDmC,kBAAkB,CAACpB,SAAS,EAAEF,aAAa,CAAC;EAC5CsB,kBAAkB,CAACJ,UAAU,EAAED,cAAc,CAAC;AAEhD;;;;"}
1
+ {"version":3,"file":"plasmic-tabs.esm.js","sources":["../src/tabs.tsx","../src/index.tsx"],"sourcesContent":["import {\n ComponentMeta,\n DataProvider,\n usePlasmicCanvasContext,\n} from '@plasmicapp/host';\nimport constate from 'constate';\nimport React, {\n cloneElement,\n createContext,\n ReactElement,\n ReactNode,\n useContext,\n useEffect,\n useRef,\n useState,\n} from 'react';\n\nconst noop = () => {\n // noop\n};\n\nfunction defaultButtonChildren(label: string) {\n return {\n type: 'default-component',\n kind: 'button',\n props: {\n children: {\n type: 'text',\n value: label,\n },\n },\n } as const;\n}\nexport interface TabsProviderProps {\n children?: ReactNode;\n initialKey?: string;\n previewKey?: string;\n previewAll?: boolean;\n}\n\nconst DebugContext = createContext(false);\n\nexport type MountMode = 'mountOneAtATime' | 'mountAllEagerly' | 'mountLazily';\n\nfunction useTabsData({\n initialKey,\n mountMode = 'mountOneAtATime',\n}: {\n initialKey?: string;\n mountMode?: MountMode;\n}) {\n const [tabKey, setTabKey] = useState<string | undefined>(initialKey);\n const [bbox, setBbox] = useState<{ left: number; width: number } | undefined>(\n undefined\n );\n return {\n tabKey,\n bbox,\n setTabKey,\n setBbox,\n mountMode,\n };\n}\n\nconst [TabsProvider, useTabsContextUnsafe] = constate(useTabsData);\n\nfunction useTabsContext() {\n const result = useTabsContextUnsafe();\n return 'setTabKey' in result ? result : undefined;\n}\nconst modulePath = '@plasmicpkgs/plasmic-tabs';\n\nexport const TabsContainerMeta: ComponentMeta<TabsProviderProps> = {\n name: 'hostless-tabs-container',\n displayName: 'Tabs Container',\n importName: 'TabsContainer',\n importPath: modulePath,\n providesData: true,\n defaultStyles: {\n width: 'stretch',\n padding: '8px',\n },\n props: {\n initialKey: {\n type: 'string',\n description: 'Key of the initially selected tab',\n defaultValue: 'tab1',\n },\n previewKey: {\n type: 'string',\n description: 'SShow this key while editing in Plasmic Studio',\n },\n previewAll: {\n type: 'boolean',\n description: 'Reveal all tab contents while editing in Plasmic Studio',\n },\n mountMode: {\n advanced: true,\n description: 'How to render/mount tab content.',\n type: 'choice',\n options: [\n {\n label: 'Mount one at a time, unmount on hide',\n value: 'mountOneAtATime',\n },\n {\n label: 'Mount all up-front, do not unmount',\n value: 'mountAllEagerly',\n },\n {\n label: 'Mount on-demand/lazily, do not unmount',\n value: 'mountLazily',\n },\n ],\n defaultValueHint: 'mountOneAtATime',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: [\n {\n type: 'hbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab1',\n children: defaultButtonChildren('Tab 1'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-button',\n props: {\n tabKey: 'tab2',\n children: defaultButtonChildren('Tab 2'),\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-underline',\n },\n ],\n },\n {\n type: 'vbox',\n children: [\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab1',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 1'],\n },\n ],\n },\n },\n {\n type: 'component',\n name: 'hostless-tab-content',\n props: {\n tabKey: 'tab2',\n children: [\n {\n type: 'vbox',\n children: ['Some content for tab 2'],\n },\n ],\n },\n },\n ],\n },\n ],\n },\n },\n },\n};\n\nexport function TabsContainer({\n children,\n initialKey,\n previewKey,\n previewAll = false,\n}: TabsProviderProps) {\n const inEditor = !!usePlasmicCanvasContext();\n return (\n <TabsProvider initialKey={initialKey}>\n <DebugContext.Provider value={inEditor && previewAll}>\n <Helper previewKey={previewKey || initialKey}>{children}</Helper>\n </DebugContext.Provider>\n </TabsProvider>\n );\n}\n\nfunction ensure<T>(x: T | undefined | null) {\n if (!x) {\n throw new Error('unexpected nil');\n }\n return x;\n}\n\nfunction Helper({\n children,\n previewKey,\n}: {\n previewKey?: string;\n children?: ReactNode;\n}) {\n const inEditor = usePlasmicCanvasContext();\n const { tabKey } = ensure(useTabsContext());\n const effectiveKey = inEditor ? previewKey || tabKey : tabKey;\n return (\n <DataProvider name={'currentTabKey'} data={effectiveKey}>\n {children}\n </DataProvider>\n );\n}\n\nexport interface TabUnderlineProps {\n className?: string;\n}\n\nexport const TabUnderlineMeta: ComponentMeta<TabUnderlineProps> = {\n name: 'hostless-tab-underline',\n displayName: 'Tab Underline',\n importName: 'TabUnderline',\n importPath: modulePath,\n props: {},\n defaultStyles: {\n background: '#7777ff',\n height: '2px',\n },\n};\n\nexport function TabUnderline({ className }: TabUnderlineProps) {\n const { bbox } = useTabsContext() ?? { bbox: undefined };\n return bbox ? (\n <div\n className={className}\n style={{\n ...JSON.parse(JSON.stringify(bbox)),\n top: undefined,\n bottom: 0,\n position: 'absolute',\n transition: '.4s ease all',\n }}\n ></div>\n ) : null;\n}\n\nexport interface TabButtonProps {\n className?: string;\n children?: ReactNode;\n tabKey?: string;\n}\n\nexport const TabButtonMeta: ComponentMeta<TabButtonProps> = {\n name: 'hostless-tab-button',\n isAttachment: true,\n displayName: 'Tab Button',\n importName: 'TabButton',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: defaultButtonChildren('Some tab'),\n },\n },\n defaultStyles: {\n width: 'hug',\n },\n};\n\nexport function TabButton({ className, children, tabKey }: TabButtonProps) {\n const tabsContext = useTabsContext();\n const ref = useRef<HTMLDivElement>(null);\n const {\n tabKey: activeKey,\n setTabKey,\n bbox,\n setBbox,\n } = tabsContext ?? {\n tabKey: undefined,\n setTabKey: noop,\n bbox: undefined,\n setBbox: noop,\n };\n useEffect(() => {\n if (tabKey === activeKey) {\n setBbox({\n width: ref.current!.offsetWidth,\n left: ref.current!.offsetLeft,\n });\n }\n }, [ref.current, setBbox, JSON.stringify(bbox), tabKey, activeKey]);\n return (\n <div className={className} ref={ref}>\n {cloneElement(React.Children.toArray(children)[0] as ReactElement, {\n isActive: tabKey && activeKey && activeKey === tabKey,\n onClick: () => {\n setTabKey(tabKey);\n },\n })}\n </div>\n );\n}\n\nexport interface TabContentProps {\n children?: ReactNode;\n tabKey?: string;\n className?: string;\n}\n\nexport const TabContentMeta: ComponentMeta<TabContentProps> = {\n name: 'hostless-tab-content',\n isAttachment: true,\n displayName: 'Tab Content',\n importName: 'TabContent',\n importPath: modulePath,\n props: {\n tabKey: {\n type: 'string',\n description: 'The answer value selecting this choice sets',\n },\n children: {\n type: 'slot',\n defaultValue: {\n type: 'vbox',\n children: {\n type: 'text',\n value: 'This is some tab content',\n },\n },\n },\n },\n};\n\nexport function TabContent({\n children,\n className,\n tabKey,\n}: TabContentProps): ReactElement {\n const tabsContext = useTabsContext();\n const previewAll = useContext(DebugContext);\n const { tabKey: activeKey, mountMode } = tabsContext ?? {\n tabKey: undefined,\n mountMode: 'mountOneAtATime',\n };\n const show = tabsContext === undefined || activeKey === tabKey || previewAll;\n const [everMounted, setEverMounted] = useState(false);\n useEffect(() => {\n if (show) {\n setEverMounted(true);\n }\n }, [show]);\n const divContent = (\n <div className={className} style={show ? {} : { display: 'none' }}>\n {children}\n </div>\n );\n switch (mountMode) {\n case 'mountOneAtATime':\n return <>{show ? children : null}</>;\n case 'mountAllEagerly':\n return divContent;\n case 'mountLazily':\n return <>{everMounted && divContent}</>;\n }\n throw new Error(`Unexpected mount mode ${mountMode}`);\n}\n","import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\n\nimport {\n TabsContainer,\n TabsContainerMeta,\n TabUnderline,\n TabUnderlineMeta,\n TabButton,\n TabButtonMeta,\n TabContent, TabContentMeta\n} from \"./tabs\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n \n _registerComponent(TabsContainer, TabsContainerMeta);\n _registerComponent(TabUnderline, TabUnderlineMeta);\n _registerComponent(TabButton, TabButtonMeta);\n _registerComponent(TabContent, TabContentMeta);\n\n}\n\nexport * from \"./tabs\";\n"],"names":["noop","defaultButtonChildren","label","type","kind","props","children","value","DebugContext","createContext","useTabsData","initialKey","mountMode","useState","tabKey","setTabKey","undefined","bbox","setBbox","constate","TabsProvider","useTabsContextUnsafe","useTabsContext","result","modulePath","TabsContainerMeta","name","displayName","importName","importPath","providesData","defaultStyles","width","padding","description","defaultValue","previewKey","previewAll","advanced","options","defaultValueHint","TabsContainer","inEditor","usePlasmicCanvasContext","React","Provider","Helper","ensure","x","Error","effectiveKey","DataProvider","data","TabUnderlineMeta","background","height","TabUnderline","className","style","JSON","parse","stringify","top","bottom","position","transition","TabButtonMeta","isAttachment","TabButton","tabsContext","ref","useRef","activeKey","useEffect","current","offsetWidth","left","offsetLeft","cloneElement","Children","toArray","isActive","onClick","TabContentMeta","TabContent","useContext","show","everMounted","setEverMounted","divContent","display","registerAll","loader","_registerComponent","Component","defaultMeta","registerComponent"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiBA,IAAMA,IAAI,GAAG,SAAPA,IAAI;;AACR,CACD;AAED,SAASC,qBAAqB,CAACC,KAAa;EAC1C,OAAO;IACLC,IAAI,EAAE,mBAAmB;IACzBC,IAAI,EAAE,QAAQ;IACdC,KAAK,EAAE;MACLC,QAAQ,EAAE;QACRH,IAAI,EAAE,MAAM;QACZI,KAAK,EAAEL;;;GAGH;AACZ;AAQA,IAAMM,YAAY,gBAAGC,aAAa,CAAC,KAAK,CAAC;AAIzC,SAASC,WAAW;MAClBC,UAAU,QAAVA,UAAU;IAAA,sBACVC,SAAS;IAATA,SAAS,+BAAG,iBAAiB;EAK7B,gBAA4BC,QAAQ,CAAqBF,UAAU,CAAC;IAA7DG,MAAM;IAAEC,SAAS;EACxB,iBAAwBF,QAAQ,CAC9BG,SAAS,CACV;IAFMC,IAAI;IAAEC,OAAO;EAGpB,OAAO;IACLJ,MAAM,EAANA,MAAM;IACNG,IAAI,EAAJA,IAAI;IACJF,SAAS,EAATA,SAAS;IACTG,OAAO,EAAPA,OAAO;IACPN,SAAS,EAATA;GACD;AACH;AAEA,6BAA6CO,QAAQ,CAACT,WAAW,CAAC;EAA3DU,YAAY;EAAEC,oBAAoB;AAEzC,SAASC,cAAc;EACrB,IAAMC,MAAM,GAAGF,oBAAoB,EAAE;EACrC,OAAO,WAAW,IAAIE,MAAM,GAAGA,MAAM,GAAGP,SAAS;AACnD;AACA,IAAMQ,UAAU,GAAG,2BAA2B;IAEjCC,iBAAiB,GAAqC;EACjEC,IAAI,EAAE,yBAAyB;EAC/BC,WAAW,EAAE,gBAAgB;EAC7BC,UAAU,EAAE,eAAe;EAC3BC,UAAU,EAAEL,UAAU;EACtBM,YAAY,EAAE,IAAI;EAClBC,aAAa,EAAE;IACbC,KAAK,EAAE,SAAS;IAChBC,OAAO,EAAE;GACV;E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ACLC,iBAAiB,CAACF,SAAS,EAAEC,WAAW,CAAC;;GAE5C;EAEDF,kBAAkB,CAACpD,aAAa,EAAEhB,iBAAiB,CAAC;EACpDoE,kBAAkB,CAACrC,YAAY,EAAEH,gBAAgB,CAAC;EAClDwC,kBAAkB,CAACzB,SAAS,EAAEF,aAAa,CAAC;EAC5C2B,kBAAkB,CAACT,UAAU,EAAED,cAAc,CAAC;AAEhD;;;;"}
package/dist/tabs.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { ComponentMeta } from '@plasmicapp/host';
2
- import { ReactNode } from 'react';
2
+ import { ReactElement, ReactNode } from 'react';
3
3
  export interface TabsProviderProps {
4
4
  children?: ReactNode;
5
5
  initialKey?: string;
6
6
  previewKey?: string;
7
7
  previewAll?: boolean;
8
8
  }
9
+ export declare type MountMode = 'mountOneAtATime' | 'mountAllEagerly' | 'mountLazily';
9
10
  export declare const TabsContainerMeta: ComponentMeta<TabsProviderProps>;
10
11
  export declare function TabsContainer({ children, initialKey, previewKey, previewAll, }: TabsProviderProps): JSX.Element;
11
12
  export interface TabUnderlineProps {
@@ -23,6 +24,7 @@ export declare function TabButton({ className, children, tabKey }: TabButtonProp
23
24
  export interface TabContentProps {
24
25
  children?: ReactNode;
25
26
  tabKey?: string;
27
+ className?: string;
26
28
  }
27
29
  export declare const TabContentMeta: ComponentMeta<TabContentProps>;
28
- export declare function TabContent({ children, tabKey }: TabContentProps): JSX.Element;
30
+ export declare function TabContent({ children, className, tabKey, }: TabContentProps): ReactElement;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.6",
2
+ "version": "0.0.9",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "scripts": {
16
16
  "start": "tsdx watch",
17
17
  "build": "tsdx build",
18
- "test": "tsdx test --passWithNoTests",
18
+ "test": "yarn --cwd=../.. test --passWithNoTests",
19
19
  "lint": "tsdx lint",
20
20
  "prepare": "if-env PREPARE_NO_BUILD=true || yarn build",
21
21
  "size": "size-limit",
@@ -57,11 +57,10 @@
57
57
  "react-dom": "^18.2.0",
58
58
  "size-limit": "^7.0.4",
59
59
  "tsdx": "^0.14.1",
60
- "tslib": "^2.3.1",
61
- "typescript": "^4.5.4"
60
+ "tslib": "^2.3.1"
62
61
  },
63
62
  "dependencies": {
64
63
  "constate": "^3.3.2"
65
64
  },
66
- "gitHead": "361c3f2e99d74b4feaeca0f27a9e8875718fcaee"
65
+ "gitHead": "c38f181fa834dca41737aa37a6dc3ad28a0f655f"
67
66
  }