Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/226 optimise dropdown for mobile devices #232

Merged
merged 55 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
ffa5074
build: add autoprefixer to storybook config
hjalmers Sep 3, 2021
9e0c166
feat: add utilities from bootstrap
hjalmers Sep 3, 2021
caf3d87
refactor: rename token for border color
hjalmers Sep 3, 2021
5848c7e
style: fix lint errors
hjalmers Sep 3, 2021
7bf483f
refactor(spacing): use bootstrap utility
hjalmers Sep 3, 2021
0820d6f
refactor(shadow): use bootstrap utility
hjalmers Sep 3, 2021
b458644
refactor(border): use bootstrap utility
hjalmers Sep 3, 2021
626ec5c
feat: add bootstrap utilities as token
hjalmers Sep 3, 2021
dfe5d43
refactor: move config tokens to separate file
hjalmers Sep 3, 2021
e3598a1
fix(typography): font map for utility generator
hjalmers Sep 3, 2021
c6f5a01
chore: clean up
hjalmers Sep 3, 2021
811da96
feat: add css grid
hjalmers Sep 3, 2021
64e9689
docs: update stories
hjalmers Sep 3, 2021
30bb636
build(chlorophyll): autoprefix and minify output
hjalmers Sep 3, 2021
69a028e
chore: bump postcss and switch to webpack5
hjalmers Sep 3, 2021
c63a87c
docs(storybook): minify css
hjalmers Sep 3, 2021
04b4912
fix(close): calc value
hjalmers Sep 3, 2021
9c191bd
feat(nx): add custom executor for scss lib
hjalmers Sep 6, 2021
80f749d
feat(nx): add release target for chlorophyll
hjalmers Sep 6, 2021
b2b8789
ci(github-actions): add release action
hjalmers Sep 6, 2021
2d51a19
chore(semantic-release): update release message
hjalmers Sep 7, 2021
365b924
ci(github-actions): add env and run with verbose
hjalmers Sep 7, 2021
41dd73d
chore(chlorophyll): add publish config to package.json
hjalmers Sep 7, 2021
8ed6af2
ci(github-actions): disable husky (git hooks) for release commit
hjalmers Sep 7, 2021
e73c864
chore(release): :package: @sebgroup/chlorophyll@1.0.0-alpha.1 [skip ci]
semantic-release-bot Sep 7, 2021
0c9ec9f
Merge branch 'main' into alpha
hjalmers Sep 14, 2021
ad83057
chore(deps): update lock file
hjalmers Sep 14, 2021
52f4af1
fix: add readme and change log to package
hjalmers Sep 14, 2021
4875f7d
chore(release): :package: @sebgroup/chlorophyll@1.0.0-alpha.2 [skip ci]
semantic-release-bot Sep 14, 2021
428a9d3
Merge branch 'main' into alpha
hjalmers Sep 29, 2021
a88d45d
chore(deps-dev): audit fix
hjalmers Sep 29, 2021
5f7a000
build: only copy fonts if they're missing
hjalmers Sep 29, 2021
23aa569
fix(sass): don't use tilde to resolve node modules
hjalmers Sep 29, 2021
d36579e
chore(deps-dev): update
hjalmers Sep 29, 2021
0bf0948
chore(release): :package: @sebgroup/chlorophyll@1.0.0-alpha.3 [skip ci]
semantic-release-bot Sep 29, 2021
e308ce1
docs(angular): fix circular dependency
hjalmers Oct 19, 2021
5512c97
chore(angular): add affected dependency to chlorophyll
hjalmers Oct 19, 2021
87aec46
Merge branch 'alpha' into feature/224-setup-release-pipeline-for-angu…
hjalmers Oct 19, 2021
cc383ea
chore(angular): add release config
hjalmers Oct 19, 2021
0489ea5
chore: update package info
hjalmers Oct 19, 2021
7e42402
ci(github-actions): release affected libs
hjalmers Oct 19, 2021
df8a671
Merge branch 'alpha' into feature/224-setup-release-pipeline-for-angu…
hjalmers Oct 19, 2021
b734406
chore: update lock file
hjalmers Oct 19, 2021
f2dc924
Merge branch 'alpha' into feature/224-setup-release-pipeline-for-angu…
hjalmers Oct 19, 2021
7b1cb2b
style: fix lint error
hjalmers Oct 19, 2021
72497dd
ci(github-actions): add fetch depth
hjalmers Oct 19, 2021
5fae621
chore(local-dev): add host config
hjalmers Oct 26, 2021
17f4057
fix(close): exclude from base button and add version for mobile
hjalmers Oct 26, 2021
6258816
feat(dropdown): add slide up style for small screens (mobile)
hjalmers Oct 26, 2021
32192b8
fix(angular-dropdown): toggle popper on screen size, optimise for mobile
hjalmers Oct 26, 2021
ee87148
refactor(dropdown): add interface for popover config
hjalmers Oct 26, 2021
0852f63
feat(dropdown): prevent scroll in background when dropdown is active
hjalmers Oct 26, 2021
55e9a4c
fix(dropdown): use transition on mobile layout only
hjalmers Oct 26, 2021
c8eddb7
ci(github-actions): release only from alpha branch
hjalmers Oct 26, 2021
a9f0cc8
chore(deps): add body scroll lock
hjalmers Oct 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Run semantic release
on:
push:
branches: [ alpha ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v2
with:
node-version: "14"

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install dependencies
run: yarn install --prefer-offline --frozen-lockfile --silent

- name: Build affected libs
# run: npx nx run chlorophyll:build
run: npx nx affected --target build --base=origin/main

- name: Release affected libs
# run: npx nx run chlorophyll:release --verbose
run: npx nx affected --target release --base=origin/main
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
HUSKY: 0
1 change: 1 addition & 0 deletions .storybook/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = {
// Add your installed PostCSS plugins here:
plugins: [
require('autoprefixer'),
require('cssnano'),
],
};
1 change: 0 additions & 1 deletion apps/angular-lib-dev/src/app/dropdown/dropdown.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { CommonModule } from '@angular/common'
import { DropdownRoutingModule } from './dropdown-routing.module'
import { DropdownComponent } from './dropdown.component'
import { ReactiveFormsModule } from '@angular/forms'
// eslint-disable-next-line
import { NggDropdownModule } from '@sebgroup/green-angular'

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { SegmentedControlRoutingModule } from './segmented-control-routing.modul
import { SegmentedControlComponent } from './segmented-control.component'
import { OptionAComponent } from './option-a/option-a.component'
import { OptionBComponent } from './option-b/option-b.component'
// eslint-disable-next-line
import { NggSegmentedControlModule } from '@sebgroup/green-angular'

@NgModule({
Expand Down
3 changes: 3 additions & 0 deletions libs/angular/ng-package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/libs/angular",
"allowedNonPeerDependencies": [
"@sebgroup/chlorophyll"
],
"lib": {
"entryFile": "src/index.ts"
}
Expand Down
23 changes: 21 additions & 2 deletions libs/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
{
"name": "@sebgroup/green-angular",
"version": "0.0.1",
"version": "0.0.0-semantically-released",
"peerDependencies": {
"@angular/common": "^12.1.0",
"@angular/core": "^12.1.0"
},
"dependencies": {
"@sebgroup/chlorophyll": "*",
"@types/body-scroll-lock": "^3.1.0",
"body-scroll-lock": "^4.0.0-beta.0",
"tslib": "^2.2.0"
}
},
"description": "Angular components built on top of @sebgroup/chlorophyll.",
"repository": {
"type": "git",
"url": "git+https://github.com/sebgroup/green.git"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"author": "Robert Hjalmers <opensource@rhj.se> (http://www.linkedin.com/in/robert-hjalmers/)",
"contributors": [],
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/sebgroup/green/labels/angular"
},
"homepage": "https://sebgroup.github.io/green/latest/angular/"
}
23 changes: 14 additions & 9 deletions libs/angular/src/lib/dropdown/dropdown.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ import { AbstractControl } from '@angular/forms'
>
{{ control.value }}
</button>
<ul nggPopoverElement tabindex="-1" autofocus>
<li
*ngFor="let option of options; let i = index"
[nggPopoverOption]="option.value"
[index]="i"
>
{{ option.key }}
</li>
</ul>
<div nggPopoverElement tabindex="-1" autofocus>
<button class="close m-4 m-sm-2 d-block d-sm-none ">
<span class="sr-only">Close</span>
</button>
<ul role="listbox">
<li
*ngFor="let option of options; let i = index"
[nggPopoverOption]="option.value"
[index]="i"
>
{{ option.key }}
</li>
</ul>
</div>
</div>
`,
//changeDetection: ChangeDetectionStrategy.OnPush
Expand Down
97 changes: 72 additions & 25 deletions libs/angular/src/lib/dropdown/popover-element.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ElementRef,
forwardRef,
HostBinding,
HostListener,
Inject,
OnDestroy,
OnInit,
Expand All @@ -17,24 +18,38 @@ import { EMPTY, fromEvent, merge, Subject } from 'rxjs'
import { NggPopoverOptionDirective } from './popover-option.directive'
import { NggPopoverDirective } from './popover.directive'
import { createPopper } from '@popperjs/core'
import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock'

@Directive({
selector: '[nggPopoverElement]',
})
export class NggPopoverElementDirective implements OnInit, OnDestroy {
_popper?: Instance
_popper?: Instance | null
_container?: ElementRef | null
$unsubscribe = new Subject()
sm = window.innerWidth <= 576
@ContentChildren(NggPopoverOptionDirective) options:
| QueryList<NggPopoverOptionDirective>
| undefined

@HostBinding('class.popover') class = true
@HostBinding('attr.role') role = 'listbox'
@HostBinding('attr.id') id = null
@HostBinding('class.d-block') show = this.popover.state.$isOpen.value
@HostBinding('class.active') show = this.popover.state.$isOpen.value
@HostBinding('attr.aria-activedescendant') activeDescendant: string | null =
null
// TODO: refactor and move to general size/device service
@HostListener('window:resize', ['$event']) onResize(event: UIEvent) {
// determine if small screen size i.e less than or equal to 576 pixels which is the breakpoint for small screens
this.sm = (event.target as Window).innerWidth <= 576
if (this.sm) {
// remove popper
this.removePopper()
} else if (!this._popper) {
// add popper
this.addPopper()
}
}

handleClickEvent(event: Event) {
// if click inside popover element...
Expand Down Expand Up @@ -96,35 +111,25 @@ export class NggPopoverElementDirective implements OnInit, OnDestroy {
this.show = isOpen // toggle visibility

if (isOpen) {
// if use body scroll lock
if (this.popover.config.useBodyScrollLock) {
this.disableBodyScrollLock()
}
// if popover is configured to use a container...
if (this.popover.config.container !== '') {
// ...add container
this.addContainer()
}
// if popover is configured to use popper.js...
if (this.popover.config.usePopper) {
// ...create popper instance for anchoring popover with trigger element
this._popper = createPopper(
this.popover.triggerElement?.nativeElement,
this._elRef.nativeElement,
{
placement: 'bottom-start',
modifiers: [
{
name: 'offset',
options: {
offset: [0, 4],
},
},
],
}
)
// detect changes once element and popper is initiated to update initial position
this._cdr.detectChanges()
this.addPopper()
}
} else {
if (this.popover.config.useBodyScrollLock) {
this.enableBodyScrollLock()
}
this.removeContainer()
this._popper?.destroy()
this.removePopper()
}
}),
switchMap((isOpen) =>
Expand Down Expand Up @@ -163,10 +168,8 @@ export class NggPopoverElementDirective implements OnInit, OnDestroy {
}

ngOnDestroy() {
// destroy popper if declared
if (this._popper) {
this._popper?.destroy()
}
this.removePopper()
this.disableBodyScrollLock()

// remove container if declared
if (this._container) {
Expand All @@ -176,6 +179,50 @@ export class NggPopoverElementDirective implements OnInit, OnDestroy {
this.$unsubscribe.complete()
}

enableBodyScrollLock() {
enableBodyScroll(this._elRef.nativeElement)
}

disableBodyScrollLock() {
disableBodyScroll(this._elRef.nativeElement)
}

addPopper() {
if (this.sm) {
return
}
if (!this._popper) {
// ...create popper instance for anchoring popover with trigger element
this._popper = createPopper(
this.popover.triggerElement?.nativeElement,
this._elRef.nativeElement,
{
placement: 'bottom-start',
modifiers: [
{
name: 'offset',
options: {
offset: [0, 4],
},
},
],
}
)
// detect changes once element and popper is initiated to update initial position
this._cdr.detectChanges()
} else {
this._popper.state.elements.reference =
this.popover.triggerElement?.nativeElement
this._popper.update().then((_) => this._cdr.detectChanges())
}
}
removePopper() {
// destroy popper if declared
if (this._popper) {
this._popper?.destroy()
this._popper = null
}
}
addContainer() {
// create global container for popover if not already present
if (!this._container) {
Expand Down
18 changes: 9 additions & 9 deletions libs/angular/src/lib/dropdown/popover.directive.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { Directive, ElementRef, Input } from '@angular/core'
import { AbstractControl } from '@angular/forms'
import { BehaviorSubject } from 'rxjs'
interface PopoverConfig {
usePopper?: boolean
container?: '' | 'body'
useBodyScrollLock?: boolean
}

@Directive({
selector: '[nggPopover]',
})
export class NggPopoverDirective {
get config(): { usePopper?: boolean; container?: '' | 'body' } {
get config(): PopoverConfig {
return this._config
}

@Input() set config(config: {
usePopper?: boolean
container?: '' | 'body'
}) {
@Input() set config(config: PopoverConfig) {
this._config = { ...this.config, ...config }
}
triggerElement?: ElementRef
private _config: {
usePopper?: boolean
container?: '' | 'body'
} = {
private _config: PopoverConfig = {
usePopper: true,
container: '',
useBodyScrollLock: true,
}
state: {
$isOpen: BehaviorSubject<boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import { componentWrapperDecorator, moduleMetadata } from '@storybook/angular'
import { APP_BASE_HREF, CommonModule } from '@angular/common'
import { RouterModule, Routes } from '@angular/router'
import { of } from 'rxjs'
import { Component } from '@angular/core'

// eslint-disable-next-line
import { OptionAComponent } from '../../../../../apps/angular-lib-dev/src/app/segmented-control/option-a/option-a.component'
// eslint-disable-next-line
import { OptionBComponent } from '../../../../../apps/angular-lib-dev/src/app/segmented-control/option-b/option-b.component'
@Component({
template: ` <p class="mt-4">Option A</p> `,
})
class OptionAComponent {}

@Component({
template: ` <p class="mt-4">Option B</p> `,
})
class OptionBComponent {}

const routes: Routes = [
{
Expand All @@ -28,7 +34,7 @@ export default {
component: NggSegmentedControlComponent,
decorators: [
moduleMetadata({
declarations: [],
declarations: [OptionAComponent, OptionBComponent],
imports: [CommonModule, RouterModule.forRoot(routes)],
providers: [{ provide: APP_BASE_HREF, useValue: '/' }],
}),
Expand Down
1 change: 1 addition & 0 deletions libs/chlorophyll/.storybook/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = {
// Add your installed PostCSS plugins here:
plugins: [
require('autoprefixer'),
require('cssnano'),
],
};
Loading