Im using Bootstrap's Togglable tabs:
http://getbootstrap.com/javascript/#tabs
Is there a way a class or attribute that will move the tabs to the right? I can add pull-right to each li but this seems a little messy as it uses the !important tag.
Using pull-right on all the list items is actually the best way to approach this. You could tidy it up a little by creating a class for the <ul>.
.tabs-right li {
float: right;
}
<div class="row">
<div class="pull-right">
<ul id="myTab" class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Home</li>
<li role="presentation">Profile</li>
<li role="presentation" class="dropdown">
Dropdown <span class="caret"></span>
<ul class="dropdown-menu" role="menu" aria-labelledby="myTabDrop1" id="myTabDrop1-contents">
<li>#fat</li>
<li>#mdo</li>
</ul>
</li>
</ul>
</div>
</div>
<div id="myTabContent" class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="home" aria-labelledby="home-tab">
<p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p>
</div>
<div role="tabpanel" class="tab-pane fade" id="profile" aria-labelledby="profile-tab">
<p>Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.</p>
</div>
<div role="tabpanel" class="tab-pane fade" id="dropdown1" aria-labelledby="dropdown1-tab">
<p>Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.</p>
</div>
<div role="tabpanel" class="tab-pane fade" id="dropdown2" aria-labelledby="dropdown2-tab">
<p>Trust fund seitan letterpress, keytar raw denim keffiyeh etsy art party before they sold out master cleanse gluten-free squid scenester freegan cosby sweater. Fanny pack portland seitan DIY, art party locavore wolf cliche high life echo park Austin. Cred vinyl keffiyeh DIY salvia PBR, banh mi before they sold out farm-to-table VHS viral locavore cosby sweater. Lomo wolf viral, mustache readymade thundercats keffiyeh craft beer marfa ethical. Wolf salvia freegan, sartorial keffiyeh echo park vegan.</p>
</div>
</div>
just wrap ul.nav.nav-tabs into div.row>div.pull-right
Related
Please I need help with making this accordion work I am not too familiar with StimulusJS. The first accordion works fine but the rest does not respond. I have attached a snippet of the code here please let me know what I am doing wrong thank you.
The script tag contains the stimulusjs code. Please I would appreciate your comments.
<script src="https://cdn.tailwindcss.com"></script>
<script type="module">
import { Application, Controller } from "https://unpkg.com/#hotwired/stimulus/dist/stimulus.js"
window.Stimulus = Application.start()
Stimulus.register("dropdown", class extends Controller {
static targets = ["background", "drop", "expand", "button"];
static values = { accordionValue: Number };
connect() {
console.log("Drop Down connected");
}
initialize() {
this.isOpen = true;
}
onToggle = (e) => {
Array.prototype.forEach.call(this.buttonTargets, function (element, index) {
element.addEventListener("click", function () {
console.log(index)
})
})
this.isOpen ? this.show() : this.hide();
this.isOpen = !this.isOpen;
};
show() {
this.dropTarget.className = "block w-full text-base font-light pt-3";
this.backgroundTarget.className = "bg-[#F0F0F0] mb-2 py-6 px-4";
this.expandTarget.innerHTML = "-";
console.log("dropdown is active");
}
hide() {
this.dropTarget.className = "hidden";
this.backgroundTarget.className = "bg-white -mb-2 w-full py-6 px-4";
this.expandTarget.innerHTML = "+";
console.log("dropdown is closed");
}
})
</script>
<div data-controller="dropdown" class="w-full flex flex-col gap-12 md:flex-row sm:max-w-[400px] md:max-w-[450px] lg:max-w-[500px] text-[#868686]">
<div class="md:min-h-[450px] w-full mt-3">
<h4 class="text-4xl font-semibold px-4 pb-3">FAQ's</h4>
<div data-dropdown-target="background" class=" py-4 px-4">
<div data-action="click->dropdown#onToggle" data-dropdown-target="button" class="cursor-pointer flex justify-between items-center">
<h5 class="text-xl font-bold">Waar hebben jullie nieuwe tuinen aangelegd? </h5><span data-dropdown-target="expand" class="font-light text-[18px] self-start">+</span>
</div>
<p data-dropdown-target="drop" class="hidden">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div data-dropdown-target="background" class=" py-4 px-4">
<div data-action="click->dropdown#onToggle" data-dropdown-target="button" class="cursor-pointer flex justify-between items-center">
<h5 class="text-xl font-bold">Waar moet een goede hovenier aan voldoen?</h5><span data-dropdown-target="expand" class="font-light text-[18px] self-start">+</span>
</div>
<p data-dropdown-target="drop" class="hidden ">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div data-dropdown-target="background" class="py-4 px-4">
<div data-action="click->dropdown#onToggle" data-dropdown-target="button" class="cursor-pointer flex justify-between items-center">
<h5 class="text-xl font-bold">Wat kost de aanleg van een nieuwe tuin? </h5><span data-dropdown-target="expand" class="font-light text-[18px] self-start">+</span>
</div>
<p data-dropdown-target="drop" class="hidden">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
<div data-dropdown-target="background" class="py-4 px-4">
<div data-action="click->dropdown#onToggle" data-dropdown-target="button" class="cursor-pointer flex justify-between items-center">
<h5 class="text-xl font-bold">Zijn de afspraken vrijblijvend?</h5><span data-dropdown-target="expand" class="font-light text-[18px] ml-auto self-start">+</span>
</div>
<p data-dropdown-target="drop" class="hidden">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
</div>
</div>
</div>
Firstly - start with the HTML
The Stimulus docs provide a good guide and one of the key principles is 'Start with the HTML'.
All modern browsers support the HTML details disclosure element, and you can find really solid documentation for this on the MDN site. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details
Using Tailwind you can get pretty far but you may need to add a plugin to style against the open attribute.
For styling, see
https://css-tricks.com/two-issues-styling-the-details-element-and-how-to-solve-them/
How to target elements with a specific data attribute with Tailwind CSS?
https://tailwindcss.com/docs/adding-custom-styles
It would probably be a bit easier without Tailwind but that is up to you.
Get as close as you can without writing a single line of JavaScript, a nicely styled single accordion item that opens & closes without additional code.
The main benefits of using native HTML elements are
Less code to maintain is always better.
Forces you to think about accessibility and keyboard control instead of rolling your own 'button' like things that are not really buttons and breaking accessibility.
Might be good enough to leave as is and move on, you may not need the 'close others when one opens' feature and you can move on to other things in your project.
Secondly - fill in the styling gaps with Stimulus
You may find you have to use some JavaScript to add/remove some classes, try your best to avoid this, but if you have to your code approach above is close enough.
You may want to be more explicit about what classes to use on the element using the Stimulus classes approach https://stimulus.hotwired.dev/reference/css-classes
Finally - add accordion like behaviour
Assuming you want some kind of behaviour like the Bootstrap accordion where expanding one item will collapse any others already open.
Below is the simplest JavaScript to have an accordion controller that closes all other items (targets) when one opens.
When the method toggle is called, it reads that event's target and then works out if it is opening or closing. If it is opening, we go through all other accordion item targets and close them.
import { Controller } from '#hotwired/stimulus';
class AccordionController extends Controller {
static targets = ['item'];
toggle({ target }) {
const isOpening = target.hasAttribute('open');
if (isOpening) {
// if opening - close the others
this.itemTargets.forEach((item) => {
if (item === target) return;
item.removeAttribute('open');
});
}
}
}
export default AccordionController;
In the HTML we declare the data-controller="accordion" on the outer container.
For each details element we add two attributes:
data-accordion-target="item" - this scopes this details element to the accordion controller's this.itemTargets array.
data-action="toggle->accordion#toggle" - this adds an event listener for the build in details toggle event, note that this event does not bubble (unlike click) hence why we need it on each details element.
<section class="prose m-5" data-controller="accordion">
<h2>Multiple 'details' element into an accordion</h2>
<details
class="py-4 px-4"
data-action="toggle->accordion#toggle"
data-accordion-target="item"
>
<summary
class="flex justify-between items-center text-xl font-bold
cursor-pointer">
Section A
</summary>
<div class="bg-[#F0F0F0] mb-2 py-6 px-4">
Content
</div>
</details>
<details
class="py-4 px-4"
data-action="toggle->accordion#toggle"
data-accordion-target="item"
>
<summary
class="flex justify-between items-center text-xl font-bold
cursor-pointer">
Section B
</summary>
<div class="bg-[#F0F0F0] mb-2 py-6 px-4">
Content
</div>
</details>
<details
class="py-4 px-4"
data-action="toggle->accordion#toggle"
data-accordion-target="item"
>
<summary
class="flex justify-between items-center text-xl font-bold
cursor-pointer">
Section C
</summary>
<div class="bg-[#F0F0F0] mb-2 py-6 px-4">
Content
</div>
</details>
</section>
General tips
Never use a div for something that is clickable, it is just going to give you a hard time, always use a button with type="button".
There are some nuances with accessibility and the details element, be sure you understand these if your application needs to be AA compliant or higher.
Lets say we have this literal array
export default {
home: {
title: 'The homepage',
list: [
'Lorem ipsum dolor sit amet, consectetur {temp1} elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
'Lorem ipsum dolor sit amet, consectetur adipiscing {temp2}, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do {temp3} incididunt ut labore et dolore magna aliqua.'
],
temp1: 'adipiscing',
temp2: 'elit',
temp3: 'eiusmod tempor',
}
}
Then I could simple replace the {temp} for strings like so
<ul class="home__list">
<li>
<BaseTransition class="home__item">
<BaseText :text="$t('home.list[0]', { temp1: $t('home.temp1') })" size="lg-fluid" />
</BaseTransition>
</li>
<li>
<BaseTransition class="home__item">
<BaseText :text="$t('home.list[1]', { temp2: $t('home.temp2') })" size="lg-fluid" />
</BaseTransition>
</li>
<li>
<BaseTransition class="vault__item">
<BaseText :text="$t('home.list[2]', { temp3: $t('home.temp3') })" size="lg-fluid" />
</BaseTransition>
</li>
</ul>
But if I need need not temp1 to be a string but a component?
<BaseTransition type="weight">{{ $t('home.temp1) }}</BaseTransition>
I've already seen this article in the docs but is using "default" components ( tag="p" ) using slots and right now I have no clue how to adapt it for my needs
The solution that worked for me
<i18n path="home.list[1]" tag="BaseTransition" class="home__item">
<template #temp2>
<BaseTransition type="weight" tag="span">
{{ $t('home.temp2') }}
</BaseTransition>
</template>
</i18n>
I am very new to GSAP and Vue.js. I am actually using it for the first time.
I am trying to do a text animation with Splittext from GSAP.
This is what I did but I am getting this error : gsap__WEBPACK_IMPORTED_MODULE_2__.SplitText is not a constructor.
I really don't understand where this come from.
<script>
import gsap from 'gsap'
import {TimelineLite, SplitText} from 'gsap';
export default {
mounted(){
this.textReveal()
},
methods : {
textReveal(){
var $text = document.querySelector(".splittext"),
mySplitText = new SplitText($text, {type:"words"}),
splitTextTimeline = gsap.timeline();
gsap.set($text, {perspective:400});
mySplitText.split({type:"chars, words"});
splitTextTimeline.from(mySplitText.chars, {duration: 0.5, scale:2, autoAlpha:0, transformOrigin:"100% 50%", ease: "back.out", stagger: 0.02});
splitTextTimeline.play();
}
}
}
</script>
<template>
<div class="help-page">
<img class="close" src="#/assets/icons/close.svg" alt="">
<div class="text-container">
<h1>What to see</h1>
<p class="splittext">Lorem ipsum dolor, sit amet consectetur adipisicing elit. Earum, quos, magnam omnis perferendis laboriosam voluptatibus aperiam eligendi rerum fugit esse, ipsum vero quis reiciendis accusantium totam soluta ad. Quia tempore aliquam dolore eligendi amet, id quae sed tempora minus dignissimos deserunt corporis debitis error delectus dicta quidem, alias eaque!</p>
</div>
</div>
</template>
Thank you for your help :)
Well, Splittext is apparently not free and that is why I can't use it ...
I can't understand where is my fault . I try to make a custom search filter.I make a search box Where I search anythings but when it is matching in my list it gives me matching output only .But its not working .It's not look like dynamic.I am using vue 2.Hopefully I forget to add something in my computed property
<template>
<div class ="container">
<div class="new">
<form >
<h1><label>Enter country name:</label></h1>
<input type="text" name="name" class="form-control" v-model="search">
</form>
</div>
<div class='new'>
<ul>
<li v-for="country in countries">{{country.name}}
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Facere dignissimos architecto quia, quisquam ad similique corporis. Laborum, error id qui consequuntur facilis est delectus velit vel ea nisi repudiandae doloribus. </p>
</li>
</ul>
</div>
</div >
</template>
<script>
export default {
data(){
return {
countries:[
{name:'AMERICA'},
{name:'INDIA'},
{name:'PAKISTAN'},
{name:'SRILANKA'},
],
search:'',
}
},
computed: {
newfuntion(){
return this.countries.filter((funtion)=>{
return funtion.match(this.search)
});
}
}
};
</script>
It looks like you are not using your computed property in your v-for.
Try changing it to this: v-for="country in newfuntion"
I'm trying to build a ionic 3 app using the movie database api.
The popular people page in my app views the list using the site's api as it would be. The problem i'm facing is when to click on the actor/actress name, the people-detail page should view everything the site has on them. But the api uses the actor/actress ID in the api. I used the person's ID as a variable and pushed it to the people-detail page (as shown below), and I retrieved it using navparams, but nothing seems to work. The browser's console shows the json contents, but I can't retrieve it in the people-detail.html.
I'm trying to find a solution to retrieve the json and view it in the people-detail.html
I need your help, thanks in advance...
note: I hid the apiKey as it's a private key.
Here is what I did to clarify:-
people.html:-
<ion-content padding>
<ion-list *ngFor="let people of peoples">
<ion-item (click)="openPeopleDetailPage(people.id)">
<ion-avatar item-start>
<img src="{{'https://image.tmdb.org/t/p/w600_and_h900_bestv2'+people.profile_path}}">
</ion-avatar>
<h2>{{people.name}}</h2>
</ion-item>
</ion-list>
</ion-content>
people.ts:-
export class PeoplePage {
constructor(public navCtrl: NavController, public navParams: NavParams, private peoplesprovider: PeoplespProvider) {
//popular peoples
this.peoplesprovider.getPeople().subscribe(data => {
console.log(data.results);
this.peoples = data.results;
});
}
ionViewDidLoad() {
console.log('ionViewDidLoad PeoplePage');
}
openPeopleDetailPage(people: any){
this.navCtrl.push(PeopleDetailPage, {people:people})
}
}
peopleProvider.ts:-
#Injectable()
export class PeoplespProvider {
people_url: string= "https://api.themoviedb.org/3/person/popular?<api_key>";
constructor(public http: HttpClient) {
console.log('Hello PeoplespProvider Provider');
}
getPeople(){
return this.http.get(this.people_url)
}
getPeopleDetail(peopleId: number){
return this.http.get('https://api.themoviedb.org/3/person/${peopleId}?
<api_key>')
}
}
people-detail.ts:-
export class PeopleDetailPage {
people: any;
detail: any;
constructor(public navCtrl: NavController, public navParams: NavParams,
private peoplesprovider: PeoplespProvider) {
this.people = this.navParams.get('people');
}
ionViewDidLoad() {
console.log('ionViewDidLoad PeopleDetailPage');
const peopleId = this.people.id;
this.peoplesprovider.getPeopleDetail(peopleId).subscribe(data => {
console.log(data);
this.people = data;
});
}
}
people-detail.html:-
<ion-content padding>
<div>
<div text-center>
<img class="people-img" src="
{{'https://image.tmdb.org/t/p/w600_and_h900_bestv2'+people?.profile_path}}">
</div>
<div>
<h1 text-center>{{people?.name}}</h1>
</div>
<div>
<ion-toolbar>
<ion-segment [(ngModel)]="controls" color="secondary">
<ion-segment-button value="info">Info</ion-segment-button>
<ion-segment-button value="movies">Movies</ion-segment-button>
<ion-segment-button value="tv-shows">TV Shows</ion-segment-button>
</ion-segment>
</ion-toolbar>
</div>
<div [ngSwitch]="controls">
<div *ngSwitchCase="'info'">
<ion-grid>
<ion-row>
<p>Born on <b>14/02/1986</b></p>
</ion-row>
<ion-row>
<p text-wrap>From <b></b></p>
</ion-row>
<ion-row>
<p>Also known as <b>Alex Daddario</b></p>
</ion-row>
</ion-grid>
<p text-wrap>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.</p>
</div>
<div *ngSwitchCase="'movies'">
<ion-list>
<ion-item>
<ion-thumbnail item-start>
<img src="assets/imgs/1.jpg">
</ion-thumbnail>
<p class="movie-year">2018</p>
<h2 text-wrap>The Big Bang Theory is here</h2>
<p class="role-name">Constance Blackwood</p>
</ion-item>
<ion-item>
<ion-thumbnail item-start>
<img src="assets/imgs/1.jpg">
</ion-thumbnail>
<p class="movie-year">2018</p>
<h2>Cher</h2>
<p class="role-name">Constance Blackwood</p>
</ion-item>
<ion-item>
<ion-thumbnail item-start>
<img src="assets/imgs/1.jpg">
</ion-thumbnail>
<p class="movie-year">2018</p>
<h2>Cher</h2>
<p class="role-name">Constance Blackwood</p>
</ion-item>
</ion-list>
</div>
<div *ngSwitchCase="'tv-shows'">
<ion-list>
<ion-item>
<ion-thumbnail item-start>
<img src="assets/imgs/1.jpg">
</ion-thumbnail>
<p class="movie-year">2018</p>
<h2 text-wrap>The Big Bang Theory is here</h2>
<p class="role-name">Constance Blackwood</p>
</ion-item>
<ion-item>
<ion-thumbnail item-start>
<img src="assets/imgs/1.jpg">
</ion-thumbnail>
<p class="movie-year">2018</p>
<h2>Cher</h2>
<p class="role-name">Constance Blackwood</p>
</ion-item>
<ion-item>
<ion-thumbnail item-start>
<img src="assets/imgs/1.jpg">
</ion-thumbnail>
<p class="movie-year">2018</p>
<h2>Cher</h2>
<p class="role-name">Constance Blackwood</p>
</ion-item>
</ion-list>
</div>
</div>
In your people.html it seems that when you're opening a person's details youre pushing the person's ID but in your people-detail.ts you assigned this id to a people variable. When you're fetching the details later, you're using
Const peopleid = this.people.id
This should not be the case. Try using
Const peopleid = this.people.
In your people.html you are saying people.id;
<ion-item (click)="openPeopleDetailPage(people.id)">
But in people-detail.ts you are saying
this.people = this.navParams.get('people');
... and then
const peopleId = this.people.id;
This code is trying to access people.id.id, but that doesn't exist (I guess?).
SOLUTION
Try using this instead:
const peopleId = this.people;
This should give you the right ID. And btw, I see that you do this.people = data; in the end of your code. I would recommend you creating a different object for this data, instead of overwriting your peopleId-object. For instance, in top of you file:
peopleData: any;
And then, you just say:
this.peopleData = data;
Remember to replace all the people.-interpolations in people-detail.html to peopleData.