I need to change the language of my calendar in the angular version 7. I have not found much documentation about this. The main thing is to change the language of the days that appear on the calendar.
!-- begin snippet: js hide: false console: true babel: false -->
import { Component, OnInit, ViewChild } from '#angular/core';
import { CalendarComponent } from 'ng-fullcalendar';
import { Options } from 'fullcalendar';
#Component({
selector: 'app-calendario',
templateUrl: './calendario.component.html',
styleUrls: ['./calendario.component.css']
})
export class CalendarioComponent implements OnInit {
//calendario
calendarOptions: Options;
displayEvent: any;
#ViewChild(CalendarComponent) ucCalendar: CalendarComponent;
constructor() { }
ngOnInit() {
this.calendarOptions = {
editable: true,
eventLimit: false,
header: {
left: '',
center: 'title',
right: 'month'
},
events: []
};
}
}
I try to add the property locale = 'es' in the calendarOptions, but it does not work,
add this to my angular json, but I do not know how to implement it
"scripts": [
"node_modules/fullcalendar/dist/locale/es.js"
]
Thanks Gabriel I make it work with this approach
First make sure you have the import of your desire lenguage
import esLocale from '#fullcalendar/core/locales/es';
import frLocale from '#fullcalendar/core/locales/fr';
In your html file, in the full-calendar selector, you should assign values to locales and locale options.
<full-calendar
defaultView="dayGridMonth"
[locales]="locales"
locale="es"
[weekends]="false"
[plugins]="calendarPlugins"></full-calendar>
Then a variable that holds all the languages that you need
locales = [esLocale, frLocale];
You can do that using the FullCalendarComponent, setting the locale code.
#ViewChild('calendar') calendarComponent: FullCalendarComponent;
and in the ngOnInit, like that:
this.calendarComponent.locales = [ { code: 'pt-br' } ];
I hope that works for you.
I suggest a simple solution "in this case, I want to change the language to French"
in your name.component.ts
import frLocale from '#fullcalendar/core/locales/fr';
calendarOptions: CalendarOptions = {
locale: frLocale, //according to the import package
events: [
{ title: 'event 1', date: '2020-04-01' },
{ title: 'event 2', date: '2020-07-15' }
]
};
in your name.component.html
<full-calendar [options]="calendarOptions"
id='fullcalendar'>
You can do that you can use getApi() on FullCalendarComponent
First Import corresponding languages in your component
import frLocale from '#fullcalendar/core/locales/fr';
import nlLocale from '#fullcalendar/core/locales/nl';
#ViewChild(FullCalendarComponent, {static: false})
calendarComponent: FullCalendarComponent;
ngAfterViewInit(): void {
this.calendarComponent.getApi().setOption('locale', nlLocale);
}
For me it worked when starting the locale inside the Full Calendar Component
#ViewChild('calendar') calendarComponent: FullCalendarComponent;
ngOnInit(): void {
this.initCalendar();
}
private initCalendar(): void {
this.calendarOptions = {
themeSystem: 'bootstrap',
bootstrapFontAwesome: false,
buttonText: {....},
dayMaxEventRows: 1,
initialView: 'dayGridMonth',
handleWindowResize: true,
headerToolbar: {.... },
events: [...],
editable: true,
selectable: true,
eventClick: this.handleEventClick.bind(this),
locales: [ { code: 'ar' }] // <==== HERE =====
}
}
Related
I using Storybook 6.4 (with angular framework)
I m trying to hide a property from auto generated doc (the args table of Storybook)
How to do that for the following story
export default {
component: MyComponent,
decorators: [moduleMetadata({ imports: [AModuleModule] })],
parameters: {
controls: { hideNoControlsWarning: true },
},
} as Meta;
type MyStory = MyComponent;
export const Default: StoryObj<MyStory> = {};
It is possible to control the auto generated output via the argTypes of Meta definition
export default {
component: MyComponent,
decorators: [moduleMetadata({ imports: [AModuleModule] })],
parameters: {
controls: { hideNoControlsWarning: true },
},
argTypes: {
aPropName: { table: { disable: true } },
anInputName: { control: { disable: true } },
}
} as Meta<MyComponent>; // Hint: type your meta object to have some code completion from your IDE for argTypes
type MyStory = MyComponent;
export const Default: StoryObj<MyStory> = {};
Et voilà :)
i want to run a method when emitting how can i get it?
When handleShow(depth is clicked), I want to run collapsed in the medhod in the setup.
or
I want to trigger the function I will write in setup
<MenuLink
:link="items"
:key="items.title"
#click.stop="handleShow(depth)"
/>
<script>
import {ref} from "vue"
import MenuLink from "./MenuLink";
export default {
name: 'MenuItems',
components: {MenuLink},
props: {
items: {type: Object, required: true},
depth: {Number},
selected: {Number},
},
data() {
return {
opensCollapsed: false
};
},
methods: {
collapsed(dep) {
console.log(dep)
}
},
setup(props, {emit}) {
const showDropdown = ref(false);
const handleShow = (depth) => {
emit('clicked', depth)
}
return {
showDropdown,
handleShow,
}
},
};
</script>
emit should only be used if you want to get an event out of your component to its parent (for example, if your component is a custom button and you want its parent to specify what would happen when clicking on it). Otherwise, you can write the code you want inside of handleShow instead of calling emit. You can also change the function name to whatever you want, just make sure it's the same inside the setup method and in the #click.stop property.
In your case (since you just console.log the result):
<MenuLink
:link="items"
:key="items.title"
#click.stop="handleShow(depth)"
/>
<script>
import {ref} from "vue"
import MenuLink from "./MenuLink";
export default {
name: 'MenuItems',
components: {MenuLink},
props: {
items: {type: Object, required: true},
depth: {Number},
selected: {Number},
},
data() {
return {
opensCollapsed: false
};
},
setup(props, {emit}) {
const showDropdown = ref(false);
const handleShow = (depth) => {
console.log(depth)
// do whatever you want here
}
return {
showDropdown,
handleShow,
}
},
};
</script>
I try to work with Storybook in my Angular project, and I run into a misterious error message, and I have no clue what's happening here.
This is my tag.component.stories.ts file:
import { CommonModule } from '#angular/common';
import { BrowserModule } from '#angular/platform-browser';
import { RouterModule } from '#angular/router';
import { Meta, moduleMetadata, Story } from '#storybook/angular';
import { AppRoutingModule } from 'src/app/app-routing.module';
import { TagComponent } from './tag.component';
export default {
title: 'Attached Tags',
component: TagComponent,
decorators: [
moduleMetadata({
declarations: [TagComponent],
imports: [BrowserModule, CommonModule, RouterModule, AppRoutingModule]
})
]
} as Meta;
const Template: Story = (args) => ({
props: {
...args
}
});
export const GreenPost = Template.bind({});
GreenPost.args = {
tag: {
id: 1,
name: 'Test tag',
color: '#bada55',
type: 'Post'
}
};
I get this error message:
Couldn't find story matching 'attached-tags--green-post'.
- Are you sure a story with that id exists?
- Please check your stories field of your main.js config.
- Also check the browser console and terminal for error messages.
So, I'm pretty sure after reading the documentation's "Simple component" section I don't have any idea how or where should I need to define any id for stories.
Here is my .storybook/main.js:
module.exports = {
"stories": [
"../src/**/*.stories.mdx",
"../src/**/*.stories.#(js|jsx|ts|tsx)"
],
"addons": [
"#storybook/addon-links",
"#storybook/addon-essentials",
"#storybook/addon-interactions"
],
"framework": "#storybook/angular",
"core": {
"builder": "webpack5"
}
}
This is the factory default I think.
Also checked the browsers console, and nothing else, just the visible message twice.
Any idea how can I solve this issue?
I try to make my series data has click event with redux, however, I got problem when I try to dispatch my function in the callback, I'm using React-Highcharts library, I've also tried to access the chart after the component mounted, but I'm not sure how to do that since there are no example on that.
import React, { Component } from 'react'
import ReactHighcharts from 'react-highcharts'
import {connect} from 'react-redux'
import autobind from 'react-autobind'
import '../style.scss'
import axios from 'axios';
import { handleKeywordTweets } from '../actions'
import { store } from '../../../app.jsx'
require('highcharts/modules/wordcloud.js')(ReactHighcharts.Highcharts)
class WordCloud extends Component {
constructor(props) {
super(props);
autobind(this);
}
render() {
const { keywords } = this.props
console.log(keywords);
let words = []
keywords.map(data => {
let obj = {}
obj.name = data.word
if(data.count < 100) {
obj.weight = 5
} else {
obj.weight = 6
}
words.push(obj)
})
let config = {
chart: {
type: 'column',
inverted: false,
height:400,
marginTop:75,
marginBottom: 20,
borderRadius: 8,
backgroundColor: "#2B2E4A",
},
tooltip: {
enabled: false
},
series: [{
type: 'wordcloud',
data: words,
name: 'Occurrences',
}],
title: {
text: 'SENTIMENTAL WORDCLOUD',
y: 40,
style: {
color: '#ADB0D0',
fontFamily: 'Montserrat'
}
},
plotOptions: {
series: {
cursor: 'pointer',
events: {
click: function(event) {
let keyword = event.point.name
axios.all([
axios.get(`/api/v1/tweets/#36,-115,7z?${keyword}`),
axios.get(`/api/v1/tweets/#36,-115,7z/sentiments?keyword=${keyword}`)
])
.then(axios.spread((tweets, sentiments) => {
console.log(tweets);
this.props.dispatch(handleKeywordTweets())
console.log(sentiments);
}))
.catch(function(error){
console.log(error);
})
}
}
}
}
}
return (
<ReactHighcharts config = {config}
style={{ "min-width": "310px", "max-width": "800px", margin:" 0 auto"}}
></ReactHighcharts>
);
}
}
const mapStateToProps = (state) => {
const { keywords } = state.places
return { keywords }
}
export default connect(mapStateToProps)(WordCloud)
Notice that you are using a non-arrow notation function as the click handler:
click: function(event) {
let keyword = event.point.name
axios.all([
axios.get(`/api/v1/tweets/#36,-115,7z?${keyword}`),
axios.get(`/api/v1/tweets/#36,-115,7z/sentiments?keyword=${keyword}`)
]).then(axios.spread((tweets, sentiments) => {
console.log(tweets);
this.props.dispatch(handleKeywordTweets())
console.log(sentiments);
})).catch(function(error){
console.log(error);
})
}
By using non-arrow notation, the function defines its own "this" value.
However, an arrow function doesn't have its own "this" value, but instead it uses the value of the enclosing execution context (in your case, "this" refers to the React class WordCloud).
Long story short, try converting the handler to arrow notation, and also try to always use arrow notation as the previous notation is pretty much obsolete :)
I have a component:
import React from 'react';
import * as styles from './RedComponent.css';
class RedComponent extends React.Component {
render () {
return <div className={ styles.red }></div>;
}
}
This is the test case:
describe('Test suite', () => {
test('RedComponent tests', () => {
const wrapper = shallow(<RedComponent />);
});
console.log(wrapper.debug());
gives
<div className={[undefined]}></div>
instead of
<div className="RedComponent__red"></div>
If I console the imported styles I get
console.log(styles); // {default: {}}
This is only in Jest test cases. Style is not undefined when the app renders in browser.
My jest config:
{
"moduleFileExtensions": [
"js"
],
"moduleDirectories": [
"node_modules"
],
"moduleNameMapper": {
"\\.(css|less)$": "identity-obj-proxy"
},
"setupFiles": [
"./test-setup.js"
],
"collectCoverageFrom": [
"src/**/*.{js}",
"!**/node_modules/**"
],
"testEnvironment": "node",
"transform": {
"^.+\\.js$": "babel-jest",
"\\.(md|ttf|txt|eot|ico|otf|svg|png|gif|woff2|woff|jpeg)$": "./file-transformer.js"
}
}
Using jest v21.2.1, identity-obj-proxy v3.0.0 and React v16.0.0.
You have to change this line
import * as styles from './RedComponent.css';
to this:
import styles from './RedComponent.css';
I assume that you are using css-loader or similar and this is just how the loader works.
Maybe worths to check the example:
https://github.com/keyanzhang/jest-css-modules-example/
I think your moduleNameMapper should be like this:
"^.+\\.(css|less)$": "identity-obj-proxy"
Create a jest/identity-obj-proxy-esm.js file with the following content:
// This works around the fact we use ES named exports for styles, e.g.:
// import * as styles from './styles.scss'.
// https://github.com/keyanzhang/identity-obj-proxy/issues/8
module.exports = new Proxy(
{},
{
get: function getter(target, key) {
if (key === '__esModule') {
// True instead of false to pretend we're an ES module.
return true;
}
return key;
},
},
);
Edit jest.config.js:
// jest.config.js
module.exports = {
...
moduleNameMapper: {
...
'\\.(css|scss)$': '<rootDir>/jest/identity-obj-proxy-esm.js',
}
};
🏆 João Vieira and https://github.com/keyz/identity-obj-proxy/issues/8#issuecomment-430241345