Skip to content

Instantly share code, notes, and snippets.

@IlCallo
IlCallo / test.spec.ts
Last active May 17, 2019 12:41
Testing code inside ngOnChanges (and in components using OnPush) using Spectator
import { Component, Directive, Host, Input, OnChanges, SimpleChanges } from '@angular/core';
import { createHostComponentFactory, SpectatorWithHost } from '@netbasal/spectator/jest';
@Component({
selector: 'simple-component',
template: '{{ name }}'
})
class SimpleComponent implements OnChanges {
@Input() name!: string;
@IlCallo
IlCallo / _quasar.variables,scss
Last active June 25, 2019 12:05
Quasar variables SCSS version
// Taken from https://quasar.dev/style/stylus-variables#Variables-list
// Manually transformed from Stylus to SCSS, MUST BE KEPT IN SYNC
// Transformation applied
// - Update maps:
// -- change '?=' assignment with ':'
// -- add the '!default;' at the end of assignments
// -- change all '{' and '}' to '(' and ')' using RegExp
// -- add surround all map keys with ''
// -- update all maps access to `map-get($map, 'key')`
@IlCallo
IlCallo / meta-mixin.js
Created October 2, 2020 18:24
Quasar Meta extension
export function LayoutMetaMixin(titleTemplateFn = title => title) {
return {
data() {
return { metaTitle: '' };
},
meta() {
return {
titleTemplate: title => {
this.metaTitle = titleTemplateFn(title);
return this.metaTitle;
import { inject, ref, provide } from '@vue/composition-api';
export function useAppBarProviders() {
const title = ref('');
function updateTitle(newTitle: string) {
title.value = newTitle;
}
provide('updateAppBarTitle', updateTitle);
@IlCallo
IlCallo / main-layout.vue
Last active September 28, 2021 14:53
swipable-bottom-sheet (Qv2 compliant)
<script lang="ts">
import { Platform, Screen } from 'quasar';
import { defineComponent, ref } from 'vue';
import SwipableBottomSheet from './swipable-bottom-sheet.vue';
export default defineComponent({
name: 'MainLayout',
components: { SwipableBottomSheet },
setup() {
const openSheet = ref(false);
@IlCallo
IlCallo / books.ts
Last active January 13, 2023 18:17
Global reactive store based on Composition API refs
// src/services/books.ts
// $fetch is a custom fetch wrapper performing common operations, we plan to release it as open source when we'll have time
// Should be easy to understand what it does
type Book = {
id: number;
title: string;
isbn: string;
price: number;
@IlCallo
IlCallo / shims-vue-formulate.d.ts
Last active August 9, 2023 13:00
Vue Formulate shim
/* eslint-disable @typescript-eslint/no-explicit-any */
declare module '@braid/vue-formulate' {
import { PluginObject } from 'vue';
export interface Context {
/** The label to display inside "add more" button on group inputs. */
addLabel: string;
/** An object of non-prop attributes passed to the input like placeholder. */
attributes: any;
/** Function that must be called when an input blurs. */
@IlCallo
IlCallo / sticky-columns.scss
Created June 10, 2021 16:03
Composable to manage sticky columns for QTable
.sticky-table .q-table {
th.sticky-cell,
td.sticky-cell {
position: sticky;
z-index: 1;
}
th.last-sticky-cell,
td.last-sticky-cell {
border-right: 2px solid rgba($color: black, $alpha: 0.12);
@IlCallo
IlCallo / xhr-uploader-plugin.ts
Created September 13, 2021 12:48
XHR Uploader + TypeScript
import { createUploaderComponent } from 'quasar';
import { computed, ExtractPropTypes, PropType, ref, Ref } from 'vue';
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
type ValueOrFunction<ValueType, Param = never> =
| ((arg: Param) => ValueType)
| ValueType;
interface QUpoaderHeaderItem {
@IlCallo
IlCallo / move.ts
Last active March 14, 2024 16:21
Apply Drag and Drop to QTable rows using SortableJs
// Taken from https://github.com/angular/components/blob/master/src/cdk/drag-drop/drag-utils.ts
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/