Copyright 2018 Jared Boice (MIT License / Open Source)
Uptown-Dropdown - Summarized Documentation
get the full documentation at gitHub.
Donations - Bitcoin: 19XgiRojJnv9VDhyW9HmF6oKQeVc7k9McU
(use this address until 2022)
Description
Uptown-Dropdown is a fully customizable react dropdown implementation that doubles as an expander. It accepts a header component or a placeholder, an optional icon, and a single component for the expandable body which decouples the dropdown from a list. Uptown-Dropdown offers adjustable orientation, optional built-in animation, applied css class names for each state of the component, switches for disabling the component and externally toggling expand/collapse states, multiple trigger types including click and hover, the ability to pass custom props to custom components, and parameter injection of the expansion state to the click handler and to optional header/icon components as a key/value of props.
Select-Inject Integration: (click here to navigate to the select-inject npm page)
if you need a customizable react multi-select system, Uptown-Dropdown can be used with Select-Inject.
Install, Import & Instantiate
Install
npm install --save uptown-dropdown
Import
;
Instantiation Example: Dropdown
// the message prop will be passed along via bodyCompProps = { message: 'hello world'}{ const BodyComp = <div className="example-expander"> <div>propsmessage</div> <div>stuff</div> <div>stuff</div> <div>stuff</div> <div>stuff</div> <div>stuff</div> <div>stuff</div> </div> ; const IconComp = { if propsexpanded return <span>^</span>; return <span>v</span>; }; const bodyCompProps = message: 'hello world' ; // strange example but you get the point // add calculateDimension={true} to apply height animation instead of a scale transformation - if you are applying borders set maintainOpacityOnAnime={false} return <section> <div>dude that dropdown is so uptown</div> <UptownDropdown name="my-uptown-component" uid=Symbol'uptown-dropdown-render-id' expanded=false // track in your app's state as needed placeholder="what is thy bidding?" // start with something simple like "select" centerPlaceholder=true linkStyles=true anime=true flexBasis="200px" maxWidth="600px" border="1px solid dimgray" borderRadius="3px" BodyComp=BodyComp IconComp=IconComp bodyCompProps=bodyCompProps triggerType="clickAndHover" /> </section> ;}
Instantiation Example: Expander
return <section> <div>dude that dropdown is so uptown</div> <UptownDropdown name="my-uptown-component" uid=Symbol'uptown-dropdown-render-id' expanded=false // track in your app's state as needed placeholder="what is thy bidding?" // start with something simple like "select" centerPlaceholder=true linkStyles=true anime=true calculateDimension=true // required for built-in animation for componentType={expander} flexBasis="200px" maxWidth="600px" border="1px solid dimgray" borderRadius="3px" BodyComp=BodyComp IconComp=IconComp bodyCompProps=bodyCompProps triggerType="click" componentType="expander" /> </section> ;}
Props
UptownDropdownpropTypes = name: PropTypesstring // becomes the name for the css pivot class, uid: PropTypes // unique identifier: passing a unique id on each render ensures accurate real-time rendering when props update expanded: PropTypesbool // toggle the state externally or merely provide a default initial state disabled: PropTypesbool // when true, the body will not be expandable placeholder: PropTypes // text || <span>some jsx</span> that will be used if HeaderComp is not provided centerPlaceholder: PropTypesbool // center aligns the placeholder text linkStyles: PropTypesbool // applies link-appropriate styles to the header: eg. { cursor: 'pointer', userSelect: 'none'} customController: PropTypesbool // disables click events, allowing you to use your own custom click events; triggerType still applies but surrenders click events to your custom controller anime: PropTypes // (true || 'uptown-anime') || (false || 'uptown-no-anime') || 'any-custom-css-class' (css class will be dynamically applied) orientation: PropTypesstring // 'vertical' || 'vertical-reverse' || 'horizontal' || 'horizontal-reverse' calculateDimension: PropTypesbool // when true (and when anime has a truthy/custom value), uptown-dropdown will calculate and apply the body max-height/max-width (vertical/horizontal) when expanded and apply 0 on collapse maintainOpacityOnAnime: PropTypesbool // when false, opacity will fade on collapse - when true, opacity will not fade on collapse prependIcon: PropTypesbool // prepends the optionally provided icon before the placeholder (it is appended after the placeholder by default) flexBasis: PropTypesstring // eg. '200px' - quick-starter setting for synchronizing the flex-basis of the container, the header, and the body minWidth: PropTypesstring // eg. '200px' - quick-starter setting for synchronizing the min-width of the container, the header, and the body minHeight: PropTypesstring // eg. '200px' - quick-starter setting for synchronizing the min-height of the container, the header, and the body maxWidth: PropTypesstring // eg. '500px' - quick-starter setting for synchronizing the max-width of the container, the header, and the body (on vertical orientations) maxHeight: PropTypesstring // eg. '500px' - quick-starter setting for synchronizing the max-height of the container, the header, and the body (on horizontal orientations) border: PropTypesstring // eg. '1px solid dimgray' - quick-starter setting for synchronizing the border of the header and the body borderRadius: PropTypesstring eg // '3px' - quick-starter setting for synchronizing the border-radius of the header and the body boxShadow: PropTypesstring // eg. '3px 3px 3px 3px black' - quick-starter setting for synchronizing the box-shadow of the header and the body hideHeader: PropTypesbool // hides the header from view so you can use the expanded prop to control the expansion/collapse state of the component without the header being rendered HeaderComp: PropTypes // custom header component - receives expanded and headerCompProps via props IconComp: PropTypes // custom icon component - receives expanded and iconCompProps via props BodyComp: PropTypesisRequired // the expandable body component - receives bodyCompProps via props headerCompProps: PropTypesobject // optional props object passed to the optional HeaderComp iconCompProps: PropTypesobject // optional props object passed to the optional IconComp bodyCompProps: PropTypesobject // optional props object passed to the required BodyComp handleClick: PropTypesfunc // the click handler callback function - receives expanded as a parameter triggerType: PropTypesstring // the different types of expansion triggers - my favorite is 'clickOrHover' (see defaultProps below) componentType: PropTypesstring // 'dropdown' || 'expander' - for absolute || relative positioning of the expanded body (respectively) mouseOutCollapseDelay: PropTypesnumber // the amount of time in milliseconds to wait prior to collapsing the body on mouseOut - eg. 1000;UptownDropdowndefaultProps = name: 'default-uptown-dropdown-name' uid: null expanded: false disabled: false placeholder: 'select' centerPlaceholder: false linkStyles: false customController: false anime: false // when true, uptown-dropdown provides built-in animation (calculateDimension is required for componentType = "expander") orientation: VERTICAL // 'vertical' || 'vertical-reverse' || 'horizontal' || 'horizontal-reverse' calculateDimension: false // required to be true for built-in animation of componentType = 'expander' (anime needs to be true as well) maintainOpacityOnAnime: null prependIcon: false flexBasis: null minWidth: null // note: you will want to manually add border and (minWidth || maxWidth || minHeight || maxHeight) in your css when applying these styles together (due to dimension added by borders) minHeight: null maxWidth: null // note: you will want to manually add border and (minWidth || maxWidth || minHeight || maxHeight) in your css when applying these styles together (due to dimension added by borders) maxHeight: null border: null // note: you will want to manually add border and (minWidth || maxWidth || minHeight || maxHeight) in your css when applying these styles together (due to dimension added by borders) borderRadius: null boxShadow: null hideHeader: false HeaderComp: null IconComp: null headerCompProps: {} iconCompProps: {} bodyCompProps: {} {} triggerType: CLICK // 'click' || 'hover' || 'clickAndHover' || 'clickOrHover' - (the preset for 'clickAndHover' basically provides an auto collapse on mouseOut) componentType: DROPDOWN // 'dropdown' || 'expander' mouseOutCollapseDelay: MINIMUM_MOUSE_OUT_COLLAPSE_DELAY // if your provided delay time is less than the minimum (55) it will fallback to the default setting;