UNPKG

4.91 kBSource Map (JSON)View Raw
1{"version":3,"file":"Box.js","sources":["../src/components/Box/Box.js"],"sourcesContent":["import React from 'react'\nimport PropTypes from 'prop-types'\nimport { Inside, useInside } from 'use-inside'\nimport { GU, RADIUS, textStyle } from '../../style'\nimport { useTheme } from '../../theme/Theme'\nimport { useLayout } from '../Layout/Layout'\nimport { warnOnce } from '../../utils'\n\nfunction Box({ heading, children, padding, ...props }) {\n const theme = useTheme()\n const [insideSplitPrimary] = useInside('Split:primary')\n const { layoutName } = useLayout()\n const fullWidth = layoutName === 'small'\n\n const defaultPadding = (fullWidth ? 2 : insideSplitPrimary ? 5 : 3) * GU\n\n if (padding === true) {\n warnOnce(\n 'Box:padding:true',\n 'Box: setting true on the padding prop is deprecated. Omit it, or set it to undefined instead.'\n )\n padding = defaultPadding\n }\n if (padding === false) {\n warnOnce(\n 'Box:padding:false',\n 'Box: setting false on the padding prop is deprecated. Use 0.'\n )\n padding = 0\n }\n\n const contentPadding = padding === undefined ? defaultPadding : padding\n\n return (\n <Inside name=\"Box\">\n <div\n as={heading ? 'section' : 'div'}\n css={`\n position: relative;\n border-radius: ${fullWidth ? 0 : RADIUS}px;\n border-style: solid;\n border-color: ${theme.border};\n border-width: ${fullWidth ? '1px 0' : '1px'};\n background: ${theme.surface};\n color: ${theme.surfaceContent};\n & + & {\n margin-top: ${2 * GU}px;\n }\n `}\n {...props}\n >\n {heading && (\n <h1\n css={`\n display: flex;\n align-items: center;\n height: ${4 * GU}px;\n padding: 0 ${defaultPadding}px;\n border-bottom: 1px solid ${theme.border};\n\n // We pass the text style and color to the heading children, so\n // that a node structure can inherit from it. Most components set\n // their color and text style, but it is something to be aware of.\n color: ${theme.surfaceContentSecondary};\n ${textStyle('label2')};\n `}\n >\n <Inside name=\"Box:heading\">{heading}</Inside>\n </h1>\n )}\n <div\n css={`\n padding: ${contentPadding}px;\n `}\n >\n <div>\n <Inside name=\"Box:content\">{children}</Inside>\n </div>\n </div>\n </div>\n </Inside>\n )\n}\n\nBox.propTypes = {\n heading: PropTypes.node,\n children: PropTypes.node,\n padding: PropTypes.oneOfType([\n PropTypes.number,\n\n // deprecated\n PropTypes.bool,\n ]),\n}\n\nexport default Box\n"],"names":["Box","heading","children","padding","props","theme","useTheme","useInside","insideSplitPrimary","useLayout","layoutName","fullWidth","defaultPadding","GU","warnOnce","contentPadding","undefined","React","Inside","RADIUS","border","surface","surfaceContent","surfaceContentSecondary","textStyle","propTypes","PropTypes","node","oneOfType","number","bool"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,SAASA,GAAT,OAAuD;AAAA,MAAxCC,OAAwC,QAAxCA,OAAwC;AAAA,MAA/BC,QAA+B,QAA/BA,QAA+B;AAAA,MAArBC,OAAqB,QAArBA,OAAqB;AAAA,MAATC,KAAS;;AACrD,MAAMC,KAAK,GAAGC,cAAQ,EAAtB;;AADqD,mBAExBC,SAAS,CAAC,eAAD,CAFe;AAAA;AAAA,MAE9CC,kBAF8C;;AAAA,mBAG9BC,gBAAS,EAHqB;AAAA,MAG7CC,UAH6C,cAG7CA,UAH6C;;AAIrD,MAAMC,SAAS,GAAGD,UAAU,KAAK,OAAjC;AAEA,MAAME,cAAc,GAAG,CAACD,SAAS,GAAG,CAAH,GAAOH,kBAAkB,GAAG,CAAH,GAAO,CAA1C,IAA+CK,YAAtE;;AAEA,MAAIV,OAAO,KAAK,IAAhB,EAAsB;AACpBW,IAAAA,oBAAQ,CACN,kBADM,EAEN,+FAFM,CAAR;AAIAX,IAAAA,OAAO,GAAGS,cAAV;AACD;;AACD,MAAIT,OAAO,KAAK,KAAhB,EAAuB;AACrBW,IAAAA,oBAAQ,CACN,mBADM,EAEN,8DAFM,CAAR;AAIAX,IAAAA,OAAO,GAAG,CAAV;AACD;;AAED,MAAMY,cAAc,GAAGZ,OAAO,KAAKa,SAAZ,GAAwBJ,cAAxB,GA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