Skip to content

Commit

Permalink
Single col Choices & fix textfield highlighting (#964)
Browse files Browse the repository at this point in the history
* Add key to highglighted words to prevent errors

* Add prop for single col mobile Choice

* fix color variable

* Remove beta version

* only allow initial optionsPerRow

* Update snapshots
  • Loading branch information
codingcircus authored Oct 7, 2020
1 parent e6d41d5 commit 167a9bf
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nukleus",
"version": "15.1.2",
"version": "15.1.3",
"description": "Shared components repo for kununu projects",
"main": "dist/components/index.js",
"repository": {
Expand Down
8 changes: 7 additions & 1 deletion src/components/Choice/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

import {queryParamsToObject} from 'utils/params';
import ThemeContext from 'utils/themeContext';
Expand Down Expand Up @@ -46,6 +47,7 @@ export default class Choice extends React.Component {
]),
reference: PropTypes.func,
requiredLabel: PropTypes.string,
mobileSingleCol: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -67,6 +69,7 @@ export default class Choice extends React.Component {
query: {},
reference: () => {},
requiredLabel: '',
mobileSingleCol: false,
};

state = {
Expand Down Expand Up @@ -174,6 +177,7 @@ export default class Choice extends React.Component {
optionsPerRow,
reference,
requiredLabel,
mobileSingleCol,
} = this.props;
const {checked} = this.state;

Expand All @@ -189,7 +193,9 @@ export default class Choice extends React.Component {

return (
<div
className={theme('formGroup')}
className={classnames(theme('formGroup'), {
[theme('mobileSingleCol')]: mobileSingleCol,
})}
id={`${name}-container`}
>

Expand Down
35 changes: 33 additions & 2 deletions src/components/Choice/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,41 @@
}
}

.mobileSingleCol .choiceContainer.choiceFlexible,
.mobileSingleCol .choiceContainer {
@media (max-width: 480px) {
display: flex;

@supports(display: grid) {
display: grid;
grid-template-columns: 1fr;
grid-auto-rows: 1fr;
border: 0;
}

.choiceButton label {
border: 1px solid $blue;
border-top: 0;
border-radius: 0;
}

.choiceButton:first-child label {
border-top: 1px solid $blue;
border-top-right-radius: $border-radius-base;
border-top-left-radius: $border-radius-base;
}

.choiceButton:last-child label{
border-bottom-right-radius: $border-radius-base;
border-bottom-left-radius: $border-radius-base;
}
}
}

@mixin options-per-row($count) {
[data-options-per-row='#{$count}'] {
display: flex;

@supports(display: grid) {
display: grid;
grid-template-columns: 1fr 1fr;
Expand Down Expand Up @@ -257,4 +288,4 @@
@include options-per-row(4);
@include options-per-row(5);
@include options-per-row(6);
@include options-per-row(7);
@include options-per-row(7);
4 changes: 2 additions & 2 deletions src/components/TextField/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,13 @@ export default class TextField extends React.Component {
onHighlight,
} = this.props;

return userInputArray.map((part) => {
return userInputArray.map((part, index) => {
if (highlightList[part.toLowerCase()]) {
onHighlight();
return (
<span
className={styles.highlighted}
key={part}
key={`${part}-${index}`} // eslint-disable-line react/no-array-index-key
>
{part}
</span>
Expand Down
1 change: 0 additions & 1 deletion src/components/TextField/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@

.textFieldLabelFlex {
display: flex;


span:last-child {
display: flex;
Expand Down
1 change: 1 addition & 0 deletions tests/__snapshots__/Choice.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,7 @@ exports[`Renders an error if errors prop is set 1`] = `
isRequired={false}
label={null}
labelHidden={false}
mobileSingleCol={false}
name="test"
onBlur={[Function]}
onChange={[Function]}
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/TextField.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ exports[`Badwords should highlight correctly 1`] = `
<span
className="highlighted"
key="bad"
key="bad-6"
>
bad
</span>
<span
className="highlighted"
key="words"
key="words-8"
>
words
</span>
Expand Down
8 changes: 4 additions & 4 deletions utils/theming.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default theme => {
return (...names) => names
const theming = theme => (...names) => names
.map(name => theme[name] || name)
.filter(x => x)
.join(" ");
}
.join(' ');

export default theming;

0 comments on commit 167a9bf

Please sign in to comment.