@primer/components
Version:
Primer react components
44 lines (42 loc) • 1.48 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from 'react';
import styled from 'styled-components';
import sx, { merge } from '../sx';
import { ActionListContainerContext } from './ActionListContainerContext';
export const ListContext = /*#__PURE__*/React.createContext({});
const ListBox = styled.ul.withConfig({
displayName: "List__ListBox",
componentId: "sc-cvbq60-0"
})(sx);
export const List = /*#__PURE__*/React.forwardRef(({
variant = 'inset',
selectionVariant,
showDividers = false,
role,
sx: sxProp = {},
...props
}, forwardedRef) => {
const styles = {
margin: 0,
paddingInlineStart: 0,
// reset ul styles
paddingY: variant === 'inset' ? 2 : 0
};
/** if list is inside a Menu, it will get a role from the Menu */
const {
listRole
} = React.useContext(ActionListContainerContext);
return /*#__PURE__*/React.createElement(ListBox, _extends({
sx: merge(styles, sxProp),
role: role || listRole
}, props, {
ref: forwardedRef
}), /*#__PURE__*/React.createElement(ListContext.Provider, {
value: {
variant,
selectionVariant,
showDividers
}
}, props.children));
});
List.displayName = 'ActionList';