Skip to content

Commit

Permalink
Merge b50df2f into b743069
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinaStoikou authored Apr 13, 2020
2 parents b743069 + b50df2f commit 8e74929
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 62 deletions.
8 changes: 8 additions & 0 deletions docs/docs/components/count.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ The component is **not** displayed while executing the search query or if there

An optional function to override the default rendered component.

- **prefix** `String` _optional_

An optional string to be displayed before the number of results.

- **suffix** `String` _optional_

An optional string to be displayed after the number of results.

## Usage when overriding template

```jsx
Expand Down
8 changes: 8 additions & 0 deletions docs/docs/components/results_per_page.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ The component is **not** displayed while executing the search query or if there

An optional function to override the default rendered component.

- **prefix** `String` _optional_

An optional string to be displayed before the number of results.

- **suffix** `String` _optional_

An optional string to be displayed after the number of results.

## Usage when overriding template

```jsx
Expand Down
24 changes: 3 additions & 21 deletions src/demos/cern-videos/Results.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ import {
Sort,
} from '../../lib/components';

const SpanWithMargin = ({ text, margin }) => {
const size = '0.5em';
let style;
switch (margin) {
case 'left':
style = { marginLeft: size };
break;
case 'right':
style = { marginRight: size };
break;
default:
style = { margin: `0 ${size}` };
}
return <span style={style}>{text}</span>;
};

export class Results extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -94,18 +78,16 @@ export class Results extends Component {
</Grid>
<Grid relaxed verticalAlign="middle">
<Grid.Column width={8}>
<SpanWithMargin text="Found" margin="right" />
<Count />
<SpanWithMargin text="results sorted by" />
<Count prefix="Found" suffix="results sorted by" />
<Sort values={this.sortValues} />
</Grid.Column>
<Grid.Column width={8} textAlign="right">
<SpanWithMargin text="Show" margin="right" />
<ResultsPerPage
prefix="Show"
suffix="results per page"
values={this.resultsPerPageValues}
defaultValue={10}
/>
<SpanWithMargin text="results per page" />
<LayoutSwitcher defaultLayout="grid" />
</Grid.Column>
</Grid>
Expand Down
19 changes: 1 addition & 18 deletions src/demos/elasticsearch/Results.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ import {
ResultsGrid,
} from '../../lib/components';

const SpanWithMargin = ({ text, margin }) => {
const size = '0.5em';
let style;
switch (margin) {
case 'left':
style = { marginLeft: size };
break;
case 'right':
style = { marginRight: size };
break;
default:
style = { margin: `0 ${size}` };
}
return <span style={style}>{text}</span>;
};

class Tags extends Component {
onClick = (event, value) => {
window.history.push({
Expand Down Expand Up @@ -113,8 +97,7 @@ export class Results extends Component {
</Grid>
<Grid relaxed verticalAlign="middle">
<Grid.Column width={8}>
<SpanWithMargin text="Found" margin="right" />
<Count />
<Count prefix="Found" />
</Grid.Column>
<Grid.Column width={8} textAlign="right">
<LayoutSwitcher defaultLayout="grid" />
Expand Down
24 changes: 3 additions & 21 deletions src/demos/zenodo/Results.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ import {
Sort,
} from '../../lib/components';

const SpanWithMargin = ({ text, margin }) => {
const size = '0.5em';
let style;
switch (margin) {
case 'left':
style = { marginLeft: size };
break;
case 'right':
style = { marginRight: size };
break;
default:
style = { margin: `0 ${size}` };
}
return <span style={style}>{text}</span>;
};

export class Results extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -93,18 +77,16 @@ export class Results extends Component {
</Grid>
<Grid relaxed verticalAlign="middle">
<Grid.Column width={8}>
<SpanWithMargin text="Found" margin="right" />
<Count />
<SpanWithMargin text="results sorted by" />
<Count prefix="Found" suffix="results sorted by" />
<Sort values={this.sortValues} />
</Grid.Column>
<Grid.Column width={8} textAlign="right">
<SpanWithMargin text="Show" margin="right" />
<ResultsPerPage
prefix="Show"
values={this.resultsPerPageValues}
defaultValue={10}
suffix="results per page"
/>
<SpanWithMargin text="results per page" />
<LayoutSwitcher defaultLayout="list" />
</Grid.Column>
</Grid>
Expand Down
22 changes: 21 additions & 1 deletion src/lib/components/Count/Count.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,29 @@ export default class Count extends Component {
return <Label color={'blue'}>{totalResults}</Label>;
}

renderSpanWithMargin = (text, margin) => {
const size = '0.5em';
let style;
switch (margin) {
case 'left':
style = { marginLeft: size };
break;
case 'right':
style = { marginRight: size };
break;
default:
style = { margin: `0 ${size}` };
}
return <span style={style}>{text}</span>;
};

render() {
const { loading, totalResults } = this.props;
const { loading, totalResults, prefix, suffix } = this.props;
return (
<ShouldRender condition={!loading && totalResults > 0}>
{this.renderSpanWithMargin(prefix, 'right')}
{this.renderElement(totalResults)}
{this.renderSpanWithMargin(suffix)}
</ShouldRender>
);
}
Expand All @@ -35,6 +53,8 @@ Count.propTypes = {
loading: PropTypes.bool.isRequired,
totalResults: PropTypes.number.isRequired,
renderElement: PropTypes.func,
prefix: PropTypes.string,
suffix: PropTypes.string,
};

Count.defaultProps = {
Expand Down
22 changes: 21 additions & 1 deletion src/lib/components/ResultsPerPage/ResultsPerPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,31 @@ export default class ResultsPerPage extends Component {
this.updateQuerySize(value);
};

renderSpanWithMargin = (text, margin) => {
const size = '0.5em';
let style;
switch (margin) {
case 'left':
style = { marginLeft: size };
break;
case 'right':
style = { marginRight: size };
break;
default:
style = { margin: `0 ${size}` };
}
return <span style={style}>{text}</span>;
};

render() {
const { loading, currentSize, totalResults } = this.props;
const { loading, currentSize, totalResults, prefix, suffix } = this.props;
return (
<ShouldRender
condition={!loading && totalResults > 0 && currentSize !== -1}
>
{this.renderSpanWithMargin(prefix, 'right')}
{this.renderElement(currentSize, this.options, this.onChange)}
{this.renderSpanWithMargin(suffix)}
</ShouldRender>
);
}
Expand All @@ -70,6 +88,8 @@ ResultsPerPage.propTypes = {
updateQuerySize: PropTypes.func.isRequired,
setInitialState: PropTypes.func.isRequired,
renderElement: PropTypes.func,
prefix: PropTypes.string,
suffix: PropTypes.string,
};

ResultsPerPage.defaultProps = {
Expand Down

0 comments on commit 8e74929

Please sign in to comment.