diff --git a/.changeset/weak-roses-decide.md b/.changeset/weak-roses-decide.md new file mode 100644 index 0000000000..1813fa1734 --- /dev/null +++ b/.changeset/weak-roses-decide.md @@ -0,0 +1,6 @@ +--- +'react-select': minor +'@react-select/docs': patch +--- + +Add classNames API and unstyled prop diff --git a/docs/examples/Experimental.tsx b/docs/examples/Experimental.tsx index 552132bcd2..7bc4a0e90f 100644 --- a/docs/examples/Experimental.tsx +++ b/docs/examples/Experimental.tsx @@ -123,6 +123,7 @@ const Group = (props: GroupProps) => { const { Heading, getStyles, + getClassNames, children, label, headingProps, @@ -136,6 +137,7 @@ const Group = (props: GroupProps) => { selectProps={selectProps} theme={theme} getStyles={getStyles} + getClassNames={getClassNames} cx={cx} {...headingProps} > diff --git a/docs/index.css b/docs/index.css index e0fc48962c..27281e215c 100644 --- a/docs/index.css +++ b/docs/index.css @@ -15,7 +15,10 @@ body { } p > a, p > a:hover, -p > a:visited { +p > a:visited, +li > a, +li > a:hover, +li > a:visited { color: #2684ff; } code { diff --git a/docs/markdown/renderer.tsx b/docs/markdown/renderer.tsx index 2bd09d27c4..f2c4202570 100644 --- a/docs/markdown/renderer.tsx +++ b/docs/markdown/renderer.tsx @@ -105,8 +105,7 @@ const Heading = (props: HeadingProps) => { store.add(nodeKey, { key: nodeKey, label, level, path: `#${slug}` }); } const css = { - marginTop: 0, - '&:not(:first-of-type)': { marginTop: 30 }, + '&:first-child': { marginTop: 0 }, }; return linkify ? ( diff --git a/docs/pages/styles/index.tsx b/docs/pages/styles/index.tsx index ba6754c518..e113c6e997 100644 --- a/docs/pages/styles/index.tsx +++ b/docs/pages/styles/index.tsx @@ -26,146 +26,128 @@ export default function Styles() { {md` # Styles - React-Select offers a flexible, light-weight styling framework which is - a thin abstraction over simple javascript objects using - [emotion](https://emotion.sh/). + React Select offers 3 main APIs for styling: + + - [The styles prop](#the-styles-prop) + - [The classNames prop](#the-classnames-prop) + - [The classNamePrefix prop](#the-classnameprefix-prop) + + ## The styles prop + + The recommended way to provide custom styles to \`react-select\` is to use the \`styles\` prop. + \`styles\` takes an object with keys to represent the various [inner components](#inner-components) that \`react-select\` is made up of. + Each inner component takes a callback function with the following signature: ~~~jsx - /** - * @param {Object} provided -- the component's default styles - * @param {Object} state -- the component's current state e.g. \`isFocused\` - * @returns {Object} - */ - function styleFn(provided, state) { - return { ...provided, color: state.isFocused ? 'blue' : 'red' }; - } + - ); - ~~~ + - ); - ~~~ + ->({ - placement, - theme: { borderRadius, spacing, colors }, -}: MenuProps): CSSObjectWithLabel => ({ +>( + { + placement, + theme: { borderRadius, spacing, colors }, + }: MenuProps, + unstyled: boolean +): CSSObjectWithLabel => ({ label: 'menu', [alignToControl(placement)]: '100%', - backgroundColor: colors.neutral0, - borderRadius: borderRadius, - boxShadow: '0 0 0 1px hsla(0, 0%, 0%, 0.1), 0 4px 11px hsla(0, 0%, 0%, 0.1)', - marginBottom: spacing.menuGutter, - marginTop: spacing.menuGutter, position: 'absolute', width: '100%', zIndex: 1, + ...(unstyled + ? {} + : { + backgroundColor: colors.neutral0, + borderRadius: borderRadius, + boxShadow: + '0 0 0 1px hsla(0, 0%, 0%, 0.1), 0 4px 11px hsla(0, 0%, 0%, 0.1)', + marginBottom: spacing.menuGutter, + marginTop: spacing.menuGutter, + }), }); const PortalPlacementContext = @@ -366,12 +375,10 @@ export const MenuPlacer = < const Menu = >( props: MenuProps ) => { - const { children, className, cx, getStyles, innerRef, innerProps } = props; - + const { children, innerRef, innerProps } = props; return (
@@ -406,18 +413,25 @@ export const menuListCSS = < Option, IsMulti extends boolean, Group extends GroupBase