Skip to content

Documentation improvements 21-10-24 #4878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions docs/ExampleWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@ interface Props {
}

interface State {
readonly isHovered: boolean;
readonly showCode: boolean;
}

export default class ExampleWrapper extends Component<Props, State> {
state: State = { isHovered: false, showCode: false };
state: State = { showCode: false };
static defaultProps = { isEditable: true };
handleEnter = () => this.setState({ isHovered: true });
handleLeave = () => this.setState({ isHovered: false });

renderCodeSample = () => {
let { raw } = this.props;
let { showCode } = this.state;
Expand Down Expand Up @@ -100,13 +98,11 @@ export default class ExampleWrapper extends Component<Props, State> {
};

render() {
const { isHovered } = this.state;

return (
<div onMouseEnter={this.handleEnter} onMouseLeave={this.handleLeave}>
<div>
<ExampleHeading>
<h4>{this.props.label}</h4>
<Actions show={isHovered}>
<Actions>
{this.renderSourceViewOption()}
{this.renderCSBButton()}
</Actions>
Expand All @@ -123,7 +119,6 @@ const ExampleHeading = (props: any) => (
css={{
alignItems: 'center',
display: 'flex',
justifyContent: 'space-between',
paddingBottom: '1em',
paddingTop: '1.25em',

Expand Down Expand Up @@ -177,9 +172,6 @@ const actionCSS: CSSObject = {
backgroundColor: colors.neutral10,
bottom: -1,
},
':focus': {
outline: 0,
},
};

interface ActionProps {
Expand Down Expand Up @@ -214,18 +206,23 @@ const AAction = ({
);
};

const Actions = ({
show,
...props
}: { readonly show: boolean } & JSX.IntrinsicElements['div']) => (
const Actions = (props: JSX.IntrinsicElements['div']) => (
<div
css={{
flex: '1 1',
alignItems: 'center',
display: 'flex',
justifyContent: 'space-between',
opacity: show ? 1 : 0.2,
justifyContent: 'flex-end',
opacity: 0.2,
transition: 'opacity 140ms',
transitionDelay: '140ms',

'&:hover': {
opacity: 1,
},
'&:focus-within': {
opacity: 1,
},
}}
{...props}
/>
Expand Down
85 changes: 41 additions & 44 deletions docs/examples/BasicSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import React, { Component, Fragment } from 'react';

import Select from 'react-select';
import { colourOptions } from '../data';
import { Note } from '../styled-components';
Copy link
Collaborator

@Methuselah96 Methuselah96 Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also remove it from the 4 other examples that use it? Not necessary, but seems like a nice to have.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Note component only seems to be used as a label. I think it might be more straight forward to import the style than the styled component but curious if there were other thoughts on keeping the label elements styled consistently (assuming it's a concern).


const Checkbox = (props: JSX.IntrinsicElements['input']) => (
<input type="checkbox" {...props} />
const Checkbox = ({ children, ...props }: JSX.IntrinsicElements['input']) => (
<label style={{ marginRight: '1em' }}>
<input type="checkbox" {...props} />
{children}
</label>
);

interface State {
Expand Down Expand Up @@ -34,9 +36,19 @@ export default class SingleSelect extends Component<{}, State> {
toggleRtl = () => this.setState((state) => ({ isRtl: !state.isRtl }));
toggleSearchable = () =>
this.setState((state) => ({ isSearchable: !state.isSearchable }));

render() {
const {
toggleClearable,
toggleDisabled,
toggleLoading,
toggleRtl,
toggleSearchable,
} = this;

const { isClearable, isSearchable, isDisabled, isLoading, isRtl } =
this.state;

return (
<Fragment>
<Select
Expand All @@ -51,47 +63,32 @@ export default class SingleSelect extends Component<{}, State> {
name="color"
options={colourOptions}
/>
<Note Tag="label">
<Checkbox
checked={isClearable}
onChange={this.toggleClearable}
id="cypress-single__clearable-checkbox"
/>
Clearable
</Note>
<Note Tag="label" style={{ marginLeft: '1em' }}>
<Checkbox
checked={isSearchable}
onChange={this.toggleSearchable}
id="cypress-single__searchable-checkbox"
/>
Searchable
</Note>
<Note Tag="label" style={{ marginLeft: '1em' }}>
<Checkbox
checked={isDisabled}
onChange={this.toggleDisabled}
id="cypress-single__disabled-checkbox"
/>
Disabled
</Note>
<Note Tag="label" style={{ marginLeft: '1em' }}>
<Checkbox
checked={isLoading}
onChange={this.toggleLoading}
id="cypress-single__loading-checkbox"
/>
Loading
</Note>
<Note Tag="label" style={{ marginLeft: '1em' }}>
<Checkbox
type="checkbox"
checked={isRtl}
onChange={this.toggleRtl}
id="cypress-single__rtl-checkbox"
/>
RTL
</Note>

<div
style={{
color: 'hsl(0, 0%, 40%)',
display: 'inline-block',
fontSize: 12,
fontStyle: 'italic',
marginTop: '1em',
}}
>
<Checkbox checked={isClearable} onChange={toggleClearable}>
Clearable
</Checkbox>
<Checkbox checked={isSearchable} onChange={toggleSearchable}>
Searchable
</Checkbox>
<Checkbox checked={isDisabled} onChange={toggleDisabled}>
Disabled
</Checkbox>
<Checkbox checked={isLoading} onChange={toggleLoading}>
Loading
</Checkbox>
<Checkbox checked={isRtl} onChange={toggleRtl}>
RTL
</Checkbox>
</div>
</Fragment>
);
}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/StyledSingle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import chroma from 'chroma-js';
import { ColourOption, colourOptions } from '../data';
import Select, { StylesConfig } from 'react-select';

const dot = (color = '#ccc') => ({
const dot = (color = 'transparent') => ({
alignItems: 'center',
display: 'flex',

Expand Down Expand Up @@ -52,7 +52,7 @@ const colourStyles: StylesConfig<ColourOption> = {
};
},
input: (styles) => ({ ...styles, ...dot() }),
placeholder: (styles) => ({ ...styles, ...dot() }),
placeholder: (styles) => ({ ...styles, ...dot('#ccc') }),
singleValue: (styles, { data }) => ({ ...styles, ...dot(data.color) }),
};

Expand Down