Skip to content

Commit

Permalink
Merge 5d62e4a into b743069
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinaStoikou committed Apr 14, 2020
2 parents b743069 + 5d62e4a commit 63f5eb0
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 66 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
8 changes: 8 additions & 0 deletions docs/docs/components/sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 sort options.

- **suffix** `String` _optional_

An optional string to be displayed after the sort options.

## Usage when overriding template

```jsx
Expand Down
8 changes: 8 additions & 0 deletions docs/docs/components/sort_by.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

Value to use when executing a search with an empty query string. When searching with an empty query, users normally expect most recent results, while searching with a defined query string, best match or any other sorting field. Default value: the value of `defaultValue` prop.

- **prefix** `String` _optional_

An optional string to be displayed before the sort options.

- **suffix** `String` _optional_

An optional string to be displayed after the sort options.

## Usage when overriding template

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

The default value to pre-select when rendering the component. For example, `"desc"`.

- **prefix** `String` _optional_

An optional string to be displayed before the sort order values.

- **suffix** `String` _optional_

An optional string to be displayed after the sort order values.

## Usage when overriding template

```jsx
Expand Down
26 changes: 4 additions & 22 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" />
<Sort values={this.sortValues} />
<Count prefix="Found" suffix="results" />
<Sort values={this.sortValues} prefix="sorted by" />
</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
26 changes: 4 additions & 22 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" />
<Sort values={this.sortValues} />
<Count prefix="Found" suffix="results" />
<Sort values={this.sortValues} prefix="sorted by" />
</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}>
{prefix && this.renderSpanWithMargin(prefix, 'right')}
{this.renderElement(totalResults)}
{suffix && 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}
>
{prefix && this.renderSpanWithMargin(prefix, 'right')}
{this.renderElement(currentSize, this.options, this.onChange)}
{suffix && 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
22 changes: 22 additions & 0 deletions src/lib/components/Sort/Sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,30 @@ export default class Sort extends Component {
this.updateQuerySorting(selected.sortBy, selected.sortOrder);
};

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 {
currentSortBy,
currentSortOrder,
loading,
totalResults,
prefix,
suffix,
} = this.props;
return (
<ShouldRender
Expand All @@ -116,12 +134,14 @@ export default class Sort extends Component {
totalResults > 0
}
>
{prefix && this.renderSpanWithMargin(prefix, 'right')}
{this.renderElement(
currentSortBy,
currentSortOrder,
this.options,
this.onChange
)}
{suffix && this.renderSpanWithMargin(suffix)}
</ShouldRender>
);
}
Expand All @@ -136,6 +156,8 @@ Sort.propTypes = {
updateQuerySorting: PropTypes.func.isRequired,
setInitialState: PropTypes.func.isRequired,
renderElement: PropTypes.func,
prefix: PropTypes.string,
suffix: PropTypes.string,
};

Sort.defaultProps = {
Expand Down
22 changes: 21 additions & 1 deletion src/lib/components/SortBy/SortBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,31 @@ export default class SortBy extends Component {
this.updateQuerySortBy(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 { currentSortBy, loading, totalResults } = this.props;
const { currentSortBy, loading, totalResults, prefix, suffix } = this.props;
return (
<ShouldRender
condition={currentSortBy !== null && !loading && totalResults > 0}
>
{prefix && this.renderSpanWithMargin(prefix, 'right')}
{this.renderElement(currentSortBy, this.options, this.onChange)}
{suffix && this.renderSpanWithMargin(suffix)}
</ShouldRender>
);
}
Expand All @@ -76,6 +94,8 @@ SortBy.propTypes = {
updateQuerySortBy: PropTypes.func.isRequired,
setInitialState: PropTypes.func.isRequired,
renderElement: PropTypes.func,
prefix: PropTypes.string,
suffix: PropTypes.string,
};

SortBy.defaultProps = {
Expand Down
Loading

0 comments on commit 63f5eb0

Please sign in to comment.