Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 76a41b4

Browse files
authored
Style update (#17)
1 parent c9bd8f0 commit 76a41b4

File tree

191 files changed

+7890
-2647
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+7890
-2647
lines changed

.github/workflows/psalm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ jobs:
3030
run: composer install -n --prefer-dist
3131

3232
- name: Run psalm
33-
run: ./vendor/bin/psalm
33+
run: ./vendor/bin/psalm --output-format=github

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
dependency-version: [prefer-lowest, prefer-stable]
2121
include:
2222
- laravel: 8.*
23-
testbench: 6.*
23+
testbench: 6.15.*
2424

2525
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
2626

.php_cs.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $finder = Symfony\Component\Finder\Finder::create()
1010
])
1111
->name('*.php')
1212
->notName('*.blade.php')
13+
->notName('Timezone.php') // disable it on this class for now to prevent linting errors
1314
->ignoreDotFiles(true)
1415
->ignoreVCS(true);
1516

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,26 @@
22

33
All notable changes to `laravel-form-components` will be documented in this file
44

5+
## 4.0.0 - 2021-03-25
6+
### Changed
7+
- Inline most tailwind class names on form components
8+
- Remove majority of styles from stylesheet
9+
- Change styling from sass to css/postcss
10+
- Enable border by default on `<x-form-group>` when it is inline and not the first child in a container
11+
- Enable margins on `<x-form-group>` by default
12+
- Change how `<x-custom-select>` "scrolls" to each option
13+
14+
### Added
15+
- Add ability to specify grid columns on `<x-checkbox-group>` component (when inline)
16+
17+
### Removed
18+
- Remove `$fixedPosition` prop from `<x-custom-select>`
19+
20+
### Fixed
21+
- Fix array to string conversion error on textarea when no value is passed in to it
22+
- Prevent `$wire` from breaking `<x-custom-select>` when not used in a livewire component
23+
- `<x-custom-select>` will now position itself correctly and will not require the `fixed-position` prop anymore (requires Popper.js)
24+
525
## 3.1.1 - 2021-03-01
626
### Fixed
727
- Prevent inputs from rendering the string `[]` when name is omitted

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
"illuminate/view": "^8.0"
2828
},
2929
"require-dev": {
30-
"blade-ui-kit/blade-heroicons": "^0.3",
31-
"friendsofphp/php-cs-fixer": "^2.16",
32-
"gajus/dindent": "^2.0",
33-
"orchestra/testbench": "^6.4",
34-
"phpunit/phpunit": "^9.4",
30+
"blade-ui-kit/blade-heroicons": "^1.0",
31+
"friendsofphp/php-cs-fixer": "^2.18",
32+
"gajus/dindent": "^2.0.2",
33+
"orchestra/testbench": "^6.15",
34+
"phpunit/phpunit": "^9.5.4",
3535
"psalm/plugin-laravel": "^1.4",
36-
"vimeo/psalm": "^4.0"
36+
"spatie/phpunit-snapshot-assertions": "^4.2",
37+
"vimeo/psalm": "^4.6"
3738
},
3839
"suggest": {
3940
"blade-ui-kit/blade-heroicons": "Required for the default icons used in this package",

config/form-components.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@
212212
'https://unpkg.com/filepond/dist/filepond.css',
213213
'https://unpkg.com/filepond/dist/filepond.js',
214214
],
215+
216+
'popper' => 'https://unpkg.com/@popperjs/core@2',
215217
],
216218

217219
/*

dist/form-components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/form-components.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"/form-components.js":"/form-components.js?id=c4316ae6fc0652830acf"}
1+
{"/form-components.js":"/form-components.js?id=599115a2fc037f2325f8"}

resources/js/components/custom-select.js

Lines changed: 43 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import findLastIndex from '../util/findLastIndex';
1111
import { normalizeOptions } from '../util/options';
1212
import { isArray } from '../util/inspect';
1313

14+
let createPopper;
15+
1416
export default function customSelect(config) {
1517
return {
1618
focusedOptionIndex: null,
@@ -31,8 +33,7 @@ export default function customSelect(config) {
3133
disabledField: 'disabled',
3234
labelField: 'label', // used for an "optgroup"'s label
3335
optionsField: 'options', // used when creating "optgroups"
34-
fixedPosition: false,
35-
positionOnTop: false,
36+
popper: null,
3637
...config,
3738

3839
get buttonDisplay() {
@@ -63,6 +64,11 @@ export default function customSelect(config) {
6364
this.open = false;
6465
this.focusedOptionIndex = null;
6566
this.search = '';
67+
68+
if (this.popper) {
69+
this.popper.destroy();
70+
this.popper = null;
71+
}
6672
},
6773

6874
clear() {
@@ -149,6 +155,12 @@ export default function customSelect(config) {
149155
},
150156

151157
init($wire = null, $dispatch = null) {
158+
createPopper = window.Popper ? window.Popper.createPopper : window.createPopper;
159+
160+
if (typeof createPopper !== 'function') {
161+
throw new TypeError(`<x-custom-select> requires Popper (https://popper.js.org)`);
162+
}
163+
152164
this.data = [...normalizeOptions(this.data, this.fieldNames)];
153165
this.options = this.data;
154166

@@ -253,6 +265,30 @@ export default function customSelect(config) {
253265
this.focusedOptionIndex = this.options.findIndex(o => ! o.disabled && ! this.isOptgroup(o));
254266
}
255267

268+
this.popper = createPopper(this.$refs.button, this.$refs.container, {
269+
placement: 'bottom-start',
270+
modifiers: [
271+
{
272+
name: 'offset',
273+
options: {
274+
offset: [0, 4],
275+
},
276+
},
277+
{
278+
name: 'preventOverflow',
279+
options: {
280+
boundary: 'clippingParents',
281+
},
282+
},
283+
{
284+
name: 'flip',
285+
options: {
286+
padding: 30,
287+
},
288+
},
289+
],
290+
});
291+
256292
this.open = true;
257293

258294
this.$nextTick(() => {
@@ -262,8 +298,6 @@ export default function customSelect(config) {
262298
});
263299
}
264300

265-
this.positionMenu();
266-
267301
this.scrollToOption(this.focusedOptionIndex);
268302
});
269303
},
@@ -353,9 +387,11 @@ export default function customSelect(config) {
353387
}
354388

355389
try {
356-
this.$refs.listbox.children[index].scrollIntoView({
357-
block: 'center',
358-
});
390+
const child = this.$refs.listbox.children[index];
391+
const offsetTop = child.offsetTop;
392+
this.$refs.listbox.scrollTop = offsetTop || 0;
393+
394+
this.$refs.listbox.children[index].focus();
359395
} catch (e) {}
360396
},
361397

@@ -366,53 +402,5 @@ export default function customSelect(config) {
366402

367403
this.openMenu();
368404
},
369-
370-
positionMenu() {
371-
if (this.fixedPosition) {
372-
return this.positionFixedMenu();
373-
}
374-
375-
this.$refs.container.style.marginTop = null;
376-
this.positionOnTop = false;
377-
378-
// give a little bit of breathing room at the bottom of the screen.
379-
const tolerance = 10;
380-
const menuHeight = this.$refs.listbox.offsetHeight;
381-
const largestHeight = window.innerHeight - menuHeight - tolerance;
382-
383-
const { top } = this.$refs.listbox.getBoundingClientRect();
384-
385-
if (top > largestHeight) {
386-
this.positionOnTop = true;
387-
this.$refs.container.style.marginTop = `-${this.$refs.button.offsetHeight + menuHeight + 20}px`
388-
}
389-
},
390-
391-
positionFixedMenu() {
392-
// So we can accurately determine where it should be placed...
393-
this.$refs.container.style.position = 'absolute';
394-
this.$refs.container.style.top = null;
395-
396-
const { width, left: buttonLeft, top: buttonTop } = this.$refs.button.getBoundingClientRect();
397-
398-
// give a little breathing room at the bottom of the screen.
399-
const tolerance = 40;
400-
const menuHeight = this.$refs.listbox.offsetHeight;
401-
const largestHeight = window.innerHeight - menuHeight - tolerance;
402-
403-
const { top } = this.$refs.container.getBoundingClientRect();
404-
405-
if (top > largestHeight) {
406-
const buttonHeight = this.$refs.button.offsetHeight;
407-
const menuTop = buttonTop - menuHeight - 25 - buttonHeight;
408-
this.$refs.container.style.top = `${menuTop}px`;
409-
} else {
410-
this.$refs.container.style.top = `${top}px`;
411-
}
412-
413-
this.$refs.container.style.position = 'fixed';
414-
this.$refs.container.style.width = `${width}px`;
415-
this.$refs.container.style.left = `${buttonLeft}px`;
416-
},
417405
};
418406
};

0 commit comments

Comments
 (0)