-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from szhsin/feat/controlled
feat: controlled accordion
- Loading branch information
Showing
22 changed files
with
310 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,9 @@ | ||
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js'; | ||
import { useTransitionMap } from 'react-transition-state'; | ||
import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js'; | ||
import { AccordionContext } from '../utils/constants.js'; | ||
import { jsx } from 'react/jsx-runtime'; | ||
|
||
var _excluded = ["allowMultiple", "transition", "transitionTimeout", "children"]; | ||
|
||
var getTransition = function getTransition(transition, name) { | ||
return transition === true || !!(transition && transition[name]); | ||
}; | ||
|
||
var AccordionProvider = function AccordionProvider(_ref) { | ||
var allowMultiple = _ref.allowMultiple, | ||
transition = _ref.transition, | ||
transitionTimeout = _ref.transitionTimeout, | ||
children = _ref.children, | ||
rest = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
|
||
var transitionMap = useTransitionMap(_extends({ | ||
singleEnter: !allowMultiple, | ||
timeout: transitionTimeout, | ||
enter: getTransition(transition, 'enter'), | ||
exit: getTransition(transition, 'exit'), | ||
preEnter: getTransition(transition, 'preEnter'), | ||
preExit: getTransition(transition, 'preExit') | ||
}, rest)); | ||
return /*#__PURE__*/jsx(AccordionContext.Provider, { | ||
value: _extends({ | ||
mountOnEnter: rest.mountOnEnter, | ||
initialEntered: rest.initialEntered | ||
}, transitionMap), | ||
children: children | ||
}); | ||
var AccordionProvider = function AccordionProvider(props) { | ||
return /*#__PURE__*/jsx(AccordionContext.Provider, _extends({}, props)); | ||
}; | ||
|
||
export { AccordionProvider }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js'; | ||
import { ACCORDION_BLOCK } from '../utils/constants.js'; | ||
import { bem } from '../utils/bem.js'; | ||
import { AccordionProvider } from './AccordionProvider.js'; | ||
import { useAccordion } from '../hooks/useAccordion.js'; | ||
import { jsx } from 'react/jsx-runtime'; | ||
|
||
var _excluded = ["providerValue", "className"]; | ||
|
||
var ControlledAccordion = function ControlledAccordion(_ref) { | ||
var providerValue = _ref.providerValue, | ||
className = _ref.className, | ||
rest = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
|
||
var _useAccordion = useAccordion(), | ||
accordionProps = _useAccordion.accordionProps; | ||
|
||
return /*#__PURE__*/jsx(AccordionProvider, { | ||
value: providerValue, | ||
children: /*#__PURE__*/jsx("div", _extends({}, rest, accordionProps, { | ||
className: bem(ACCORDION_BLOCK, undefined, undefined, className) | ||
})) | ||
}); | ||
}; | ||
|
||
export { ControlledAccordion }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js'; | ||
import { useTransitionMap } from 'react-transition-state'; | ||
|
||
var _excluded = ["allowMultiple", "transition", "transitionTimeout"]; | ||
|
||
var getTransition = function getTransition(transition, name) { | ||
return transition === true || !!(transition && transition[name]); | ||
}; | ||
|
||
var useAccordionProvider = function useAccordionProvider(_temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
allowMultiple = _ref.allowMultiple, | ||
transition = _ref.transition, | ||
transitionTimeout = _ref.transitionTimeout, | ||
rest = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
|
||
var transitionMap = useTransitionMap(_extends({ | ||
singleEnter: !allowMultiple, | ||
timeout: transitionTimeout, | ||
enter: getTransition(transition, 'enter'), | ||
exit: getTransition(transition, 'exit'), | ||
preEnter: getTransition(transition, 'preEnter'), | ||
preExit: getTransition(transition, 'preExit') | ||
}, rest)); | ||
return _extends({ | ||
mountOnEnter: !!rest.mountOnEnter, | ||
initialEntered: !!rest.initialEntered | ||
}, transitionMap); | ||
}; | ||
|
||
export { useAccordionProvider }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { objectWithoutPropertiesLoose as _objectWithoutPropertiesLoose, extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js'; | ||
import { useTransitionMap } from 'react-transition-state'; | ||
|
||
var _excluded = ["allowMultiple", "transition", "transitionTimeout"]; | ||
|
||
var getTransition = function getTransition(transition, name) { | ||
return transition === true || !!(transition && transition[name]); | ||
}; | ||
|
||
var useAccordionState = function useAccordionState(_temp) { | ||
var _ref = _temp === void 0 ? {} : _temp, | ||
allowMultiple = _ref.allowMultiple, | ||
transition = _ref.transition, | ||
transitionTimeout = _ref.transitionTimeout, | ||
rest = _objectWithoutPropertiesLoose(_ref, _excluded); | ||
|
||
var transitionMap = useTransitionMap(_extends({ | ||
singleEnter: !allowMultiple, | ||
timeout: transitionTimeout, | ||
enter: getTransition(transition, 'enter'), | ||
exit: getTransition(transition, 'exit'), | ||
preEnter: getTransition(transition, 'preEnter'), | ||
preExit: getTransition(transition, 'preExit') | ||
}, rest)); | ||
return _extends({ | ||
mountOnEnter: !!rest.mountOnEnter, | ||
initialEntered: !!rest.initialEntered | ||
}, transitionMap); | ||
}; | ||
|
||
export { useAccordionState }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { Accordion } from './components/Accordion.js'; | ||
export { ControlledAccordion } from './components/ControlledAccordion.js'; | ||
export { AccordionItem } from './components/AccordionItem.js'; | ||
export { useAccordionItem } from './hooks/useAccordionItem.js'; | ||
export { useAccordionProvider } from './hooks/useAccordionProvider.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.