Skip to content

Commit dd4d996

Browse files
authored
Psl 1468 css improvements from enes feedback (#26)
* update dev script * decrease specificity of css selectors * use exact versions of storybook * fix docs page formatting * lower specificity css selectors * set isOpen to false for no results * simplify sb docs page layouts * add autocompleteClassName * add custom styles stories * smoother image loading state * refactor custom styles example code * update readme image * add repo workflows to readme * improve phrasing
1 parent 02af9b8 commit dd4d996

24 files changed

+258
-111
lines changed

.storybook/custom-styles-story.css

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
.cio-autocomplete.custom-autocomplete-styles form {
2+
height: 44px;
3+
width: 600px;
4+
border-radius: 8px;
5+
background-color: rgb(247, 247, 247);
6+
}
7+
8+
.cio-autocomplete.custom-autocomplete-styles .cio-input {
9+
font-size: 1rem;
10+
font-weight: bold;
11+
}
12+
13+
.cio-autocomplete.custom-autocomplete-styles .cio-form button {
14+
width: 44px;
15+
}
16+
17+
.cio-autocomplete.custom-autocomplete-styles .cio-clear-btn {
18+
right: 24px;
19+
}
20+
.cio-autocomplete.custom-autocomplete-styles .cio-icon {
21+
justify-content: center;
22+
}
23+
24+
.cio-autocomplete.custom-autocomplete-styles .cio-sectionName {
25+
font-size: 1rem;
26+
margin: 5px 3px;
27+
}
28+
29+
.cio-autocomplete.custom-autocomplete-styles .cio-results {
30+
width: 620px;
31+
max-height: 334px;
32+
overflow: hidden;
33+
border-radius: 0px 0px 8px 8px;
34+
color: rgb(51, 51, 51);
35+
}
36+
37+
.cio-autocomplete.custom-autocomplete-styles .cio-item-SearchSuggestions {
38+
width: 150px;
39+
}
40+
41+
.cio-autocomplete.custom-autocomplete-styles .Products .cio-item {
42+
display: inline-flex;
43+
align-items: center;
44+
width: 25%;
45+
max-height: 140px;
46+
height: 140px;
47+
margin: 0;
48+
padding: 5px 0;
49+
}
50+
51+
.cio-autocomplete.custom-autocomplete-styles .Products p {
52+
padding: 5px 5px 0;
53+
overflow: hidden;
54+
}
55+
56+
.cio-autocomplete.custom-autocomplete-styles .cio-item img {
57+
max-height: 100px;
58+
}

.storybook/main.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ module.exports = {
1111
options: {}
1212
},
1313
docs: {
14-
enabled: false,
15-
defaultName: 'Docs',
1614
autodocs: true
1715
}
1816
};

.storybook/preview.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { Title, Description, Stories } from '@storybook/addon-docs';
2+
import './custom-styles-story.css';
3+
import './storybook-styles.css';
24

35
export const parameters = {
46
actions: { argTypesRegex: '^on.*' },

.storybook/storybook-styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.docs-story > div:first-child {
2+
min-height: 500px;
3+
background-color: #212425;
4+
}

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This UI Library provides React components that manage fetching and rendering log
66

77
[Our storybook docs](https://constructor-io.github.io/cio-autocomplete-ts) are the best place to explore the behavior and configuration options for this UI Library.
88

9-
![Autocomplete](docs-images/autocomplete.png)
9+
![Autocomplete](assets/autosuggest-ui.gif)
1010

1111
## How to use this UI Library
1212

@@ -42,11 +42,12 @@ function YourComponent() {
4242
getLabelProps,
4343
getInputProps,
4444
getMenuProps,
45-
getItemProps
45+
getItemProps,
46+
autocompleteClassName
4647
} = useCioAutocomplete(args);
4748

4849
return (
49-
<div className='cio-autocomplete'>
50+
<div className={autocompleteClassName}>
5051
<form {...getFormProps()}>
5152
<label {...getLabelProps()} hidden>
5253
Search
@@ -96,16 +97,29 @@ function YourComponent() {
9697
}
9798
```
9899
100+
## Custom Styling
101+
102+
### Library defaults
103+
104+
This library provides some default styles. These default styles can be used as a foundation to build on top of or just as a reference for you to replace completely. All default styles in this library are scoped within the `.cio-autocomplete` css selector.
105+
106+
- If you would like to remove all default styling, simply pass an empty string or your own custom autocomplete container className as the value for the `autocompleteClassName` option
107+
- If you would like to layer your own custom styles on top of the library default styles, you can do so by passing additional className(s) of your choosing `autocompleteClassName='cio-autocomplete custom-autocomplete-container'`
108+
99109
## Local Development
100110
101111
### Development scripts
102112
103113
```bash
104114
npm ci # install dependencies for local dev
105-
npm run storybook # start a local dev server for Storybook
115+
npm run dev # start a local dev server for Storybook
106116
npm run lint # run linter
107117
```
108118
119+
### Repo Workflows
120+
121+
- [Version and Release](https://constructor.slab.com/posts/autosuggest-ui-version-and-release-jqouccw5)
122+
109123
### Maintain Library
110124
111125
```bash

assets/autosuggest-ui.gif

414 KB
Loading

docs-images/autocomplete.png

-559 KB
Binary file not shown.

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lint": "eslint src --ext js,ts,jsx,tsx",
1212
"copy-files": "copyfiles -u 1 src/**/*.css lib/src",
1313
"prepare": "husky install",
14-
"storybook": "storybook dev -p 6006",
14+
"dev": "storybook dev -p 6006",
1515
"storybook:ci": "storybook dev --ci --quiet -p 6006",
1616
"test-storybook": "test-storybook",
1717
"test-storybook:watch": "test-storybook --watch",
@@ -34,7 +34,7 @@
3434
"@storybook/addon-interactions": "^7.0.0-beta.15",
3535
"@storybook/addon-links": "^7.0.0-beta.15",
3636
"@storybook/jest": "^0.0.11-next.0",
37-
"@storybook/react-webpack5": "^7.0.0-beta.15",
37+
"@storybook/react-webpack5": "7.0.0-beta.15",
3838
"@storybook/test-runner": "^0.10.0-next.4",
3939
"@storybook/testing-library": "^0.0.14-next.1",
4040
"@types/react": "^18.0.20",
Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
.cio-autocomplete {
2-
font-family: Arial, Helvetica, sans-serif;
2+
position: relative;
3+
height: 2rem;
34
padding: 20px;
5+
font-family: Arial, Helvetica, sans-serif;
46
}
57

6-
.cio-autocomplete .cio-items {
8+
.cio-autocomplete .cio-section-items {
79
padding: 0;
810
}
911

@@ -17,22 +19,19 @@
1719
width: 100%;
1820
}
1921

20-
.cio-autocomplete .products.cio-section .cio-item {
22+
.cio-autocomplete .products .cio-item {
2123
align-items: center;
2224
justify-content: start;
2325
}
2426

25-
.cio-autocomplete .products.cio-section .cio-items {
27+
.cio-autocomplete .products .cio-section-items {
2628
display: flex;
2729
}
2830

2931
.cio-autocomplete .cio-form {
3032
position: relative;
31-
z-index: 100;
32-
width: 300px;
33-
top: 0px;
34-
right: -8px;
35-
height: 30px;
33+
height: 100%;
34+
width: 24rem;
3635
}
3736

3837
.cio-autocomplete .cio-input {
@@ -43,42 +42,44 @@
4342
border-radius: 3px;
4443
}
4544

46-
.cio-autocomplete .cio-form .cio-btn,
47-
.cio-autocomplete .cio-form .cio-clear-btn {
45+
.cio-autocomplete .cio-submit-btn,
46+
.cio-autocomplete .cio-clear-btn {
4847
position: absolute;
4948
top: 1px;
5049
bottom: -1px;
5150
right: -21px;
5251
}
5352

54-
.cio-autocomplete .cio-form .cio-btn[type='submit'] {
53+
.cio-autocomplete .cio-submit-btn {
5554
right: -21px;
5655
}
5756

58-
.cio-autocomplete .cio-form .cio-clear-btn {
57+
.cio-autocomplete .cio-clear-btn {
5958
right: 10px;
6059
}
6160

62-
.cio-autocomplete .cio-form .cio-icon {
61+
.cio-autocomplete .cio-icon {
6362
display: flex;
6463
}
6564

6665
.cio-autocomplete .cio-results {
66+
position: absolute;
6767
background-color: white;
6868
gap: 20px;
6969
padding-left: 0px;
7070
list-style: none;
7171
display: flex;
7272
flex-direction: row;
7373
z-index: 1000;
74+
margin-top: 5px;
7475
}
7576

7677
.cio-autocomplete .cio-sectionName {
7778
margin: 15px 0 20px 0;
7879
font-size: 22px;
7980
}
8081

81-
.cio-autocomplete .cio-results .cio-section.searchSuggestions .cio-items {
82+
.cio-autocomplete .searchSuggestions .cio-section-items {
8283
flex-direction: column;
8384
min-width: 200px;
8485
}
@@ -88,27 +89,20 @@
8889
}
8990

9091
.cio-autocomplete .cio-item {
91-
padding: 10px;
92+
padding: 5px;
9293
margin: 1px;
9394
border-bottom: 3px solid transparent;
9495
}
9596

97+
.cio-autocomplete .cio-item p {
98+
margin: 0;
99+
}
100+
96101
.cio-autocomplete .cio-item img {
97102
max-width: 100px;
98103
}
99104

100-
.cio-autocomplete [aria-selected='true'] {
105+
.cio-autocomplete .cio-item[aria-selected='true'] {
101106
background-color: hsl(0, 0%, 90%);
102107
border-radius: 4px;
103108
}
104-
105-
.cio-autocomplete .cio-results[role='listbox'].showing-content {
106-
position: relative;
107-
top: 2px;
108-
left: 8px;
109-
max-width: 90vw;
110-
background: white;
111-
margin: 0px;
112-
box-shadow: 0 2px 2px 1px grey;
113-
overflow: auto;
114-
}

0 commit comments

Comments
 (0)