Ionic - Angular - Create botom modal / popup - ionic-framework

I want to create a pop up under ionic that appears at the bottom and disappears when you click above it exactly like on the Youtube application when you click on the middle button.
How can i do that ?
This example image also shows well.

This is a possible solution :
// ------------------- TS CODE -----------------------------
constructor(public modalController: ModalController) {}
openBottomPopUp() {
this.modalController
.create(
{
component: PopUpPageToDisplayPage,
backdropDismiss: true,
swipeToClose: true,
cssClass: 'bottom-pop-up'
})
.then(modal => {
modal.present().then();
});
}
// ------------------- SCSS CODE -----------------------------
.bottom-modal {
.modal-wrapper {
width: 100%;
height: 35%;
position: absolute;
bottom: 0;
border-radius: 10% 10% 0 0;
}
.modal-shadow {
position: absolute;
height: 35%;
bottom: 0;
}
}
the modal-shadow must also be changed so that the pop up disappears when clicked outside. The height can be defined according to your needs.
PopUpPageToDisplayPage is the page you want to display in the popup.
You can use all parameters of ion-modal (https://ionicframework.com/docs/api/modal)

An Ionic implementation exists for this component through the ActionSheetController:
constructor(private actionSheetController: ActionSheetController) { }
async open() {
(await this.actionSheetController.create({
buttons: [
{text: 'item 1'},
{text: 'item 2'},
{text: 'item 3', handler: () => console.log('clicked')},
{text: 'cancel', role: 'cancel'},
]
})).present();
}

Related

Why aren't these react-data-grid columns resizable?

I'd like to have a react-data-grid with editable data and resizable columns. Only the last column of my example can be resized.
I have combined 'Basic Editing' and 'Column Resizing' from https://adazzle.github.io/react-data-grid/docs/examples/column-resizing.
import React from 'react';
import ReactDataGrid from 'react-data-grid';
const defaultColumnProperties = {
editable: true,
resizable: true,
width: 120,
};
const columns = [
{ key: 'id', name: 'ID' },
{ key: 'title', name: 'Title' },
{ key: 'complete', name: 'Complete' },
].map(c => ({ ...c, ...defaultColumnProperties }));;
const rows = [
{ id: 0, title: 'Task 1', complete: 20 },
{ id: 1, title: 'Task 2', complete: 40 },
];
class Example extends React.Component {
state = { rows };
onGridRowsUpdated = ({ fromRow, toRow, updated }) => {
this.setState(state => {
const rows = state.rows.slice();
for (let i = fromRow; i <= toRow; i++) {
rows[i] = { ...rows[i], ...updated };
}
return { rows };
});
};
render() {
return (
<ReactDataGrid
columns={columns}
rowGetter={i => this.state.rows[i]}
rowsCount={this.state.rows.length}
minHeight={500}
onColumnResize={(idx, width) =>
console.log(`Column ${idx} has been resized to ${width}`)
}
onGridRowsUpdated={this.onGridRowsUpdated}
enableCellSelect
/>
);
}
}
I expect to be able to grab the vertical separator between column 1 and 2, and drag to widen column 1, but the only grabbable column separator is after the last column, and so the only column I can resize is the last column.
Add this line to index.html
<link rel="stylesheet" media="screen" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css">
Discovered by diffing another project with working column resizing and this problem project.
While adding Bootstrap CSS does resolve the issue, the simpler solution is to just add the piece of the BS CSS that is needed to regain the box borders:
styles.css
* {
box-sizing: border-box;
}
I just scoped it to the component that is using react-data-grid like so:
styles.scss
#myComponent {
* {
box-sizing: border-box;
}
}

Is there a way to programme bingmap's infobox close button?

In the bingmaps documentation, you can add custom actions to the infobox. I would like to know if there's a similar way to program the default closeButton?
Ideally, I would like to be able to do something like this:
const infobox = new Microsoft.Maps.Infobox(selectedTipCoordinates, {
title: selectedTip.title,
description: selectedTip.description,
closeButton: () => console.log('hello')
});
Unfortunately close event handler could not be customized via InfoboxOptions object, so you could consider either to implement a custom HTML Infobox or override info window click handler. The following example demonstrates how to keep info window opened once close button is clicked and add a custom action:
Microsoft.Maps.Events.addHandler(infobox, 'click', handleClickInfoBox);
function handleClickInfoBox(e){
var isCloseAction = e.originalEvent.target.className == "infobox-close-img";
if(isCloseAction){
//keep info window open..
e.target.setOptions({visible: true});
//apply some custom actions..
console.log("Close button clicked");
}
}
function loadMapScenario() {
var map = new Microsoft.Maps.Map(document.getElementById("myMap"), {
center: new Microsoft.Maps.Location(47.60357, -122.32945)
});
var infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
title: "Title",
description: "Description",
actions: [
{
label: "Handler1",
eventHandler: function() {
console.log("Handler1");
}
},
{
label: "Handler2",
eventHandler: function() {
console.log("Handler2");
}
},
{
label: "Handler3",
eventHandler: function() {
console.log("Handler3");
}
}
]
});
infobox.setMap(map);
Microsoft.Maps.Events.addHandler(infobox, 'click', handleClickInfoBox);
}
function handleClickInfoBox(e){
var isCloseAction = e.originalEvent.target.className == "infobox-close-img";
if(isCloseAction){
//keep info window open..
e.target.setOptions({visible: true});
//apply some custom actions..
console.log("Close button clicked");
}
}
body{
margin:0;
padding:0;
overflow:hidden;
}
<script type='text/javascript' src='https://www.bing.com/api/maps/mapcontrol?key=&callback=loadMapScenario' async defer></script>
<div id='myMap' style='width: 100vw; height: 100vh;'></div>
No, I don't think there's a way to wire the behavior of default close button differently. That said, you can approximate the desired outcome with a little more work: creating a custom infobox with the same style and then you'll have 100% control:
e.g. (notice the onClick handler on the close button div):
var center = map.getCenter();
var infoboxTemplate = '<div class="Infobox" style=""><a class="infobox-close" href="javascript:void(0)" onClick="function test(){ alert(\'test!\'); } test(); return false;" style=""><img class="infobox-close-img" src="data:image/svg+xml;base64,PHN2ZyBoZWlnaHQ9IjE0cHgiIHdpZHRoPSIxNHB4IiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiPjxwYXRoIGQ9Ik03LDBDMy4xMzQsMCwwLDMuMTM0LDAsN2MwLDMuODY3LDMuMTM0LDcsNyw3YzMuODY3LDAsNy0zLjEzMyw3LTdDMTQsMy4xMzQsMTAuODY3LDAsNywweiBNMTAuNSw5LjVsLTEsMUw3LDhsLTIuNSwyLjVsLTEtMUw2LDdMMy41LDQuNWwxLTFMNyw2bDIuNS0yLjVsMSwxTDgsN0wxMC41LDkuNXoiLz48L3N2Zz4=" alt="close infobox"></a><div class="infobox-body" style="max-width: 256px; max-height: 126px; width: 125px;"><div class="infobox-title" >{title}</div><div class="infobox-info" style=""><div>{description}</div></div><div class="infobox-actions" style="display: none;"><ul class="infobox-actions-list"><div></div></ul></div></div><div class="infobox-stalk" style="top: 73.8px; left: 55.5px;"></div></div>';
var infobox = new Microsoft.Maps.Infobox(center, {
htmlContent: infoboxTemplate.replace('{title}', 'myTitle').replace('{description}', 'myDescription'),
offset: new Microsoft.Maps.Point(-64, 16)
});

Alert Controller - css button

I am making an ionic app with version 3.20.0. I'm using alert controller and I add three button ,Annuler ,ok and Scan.
I want to place it like in the photo below:
my css code in ionic like that:
.myalert .alert-wrapper {
padding: 0;
flex-wrap: wrap;
input.alert-input:nth-child(1){
flex: 0 0 60%;
max-width: 80%;
}
button.alert-button:nth-child(1) {
background-image:url('../assets/imgs/icon.png');
background-repeat: no-repeat;
background-position: center;
max-width: 40%;
}
}
.myalert button.alert-button-group {
flex: 0 0 50%;
max-width: 50%;
}
.myalert .alert-button-group-vertical {
flex-direction: row;
}
and my script ionic to show alert is like that ,i need help to show it
like photo below
showPrompt() {
this.donebtn = true;
let prompt = this.alertCtrl.create({
title: 'Espace Client',
message: "Tapez votre code secret",
cssClass: 'myalert',
inputs: [{
name: 'code',
placeholder: 'Mot de passe',
type: 'password',
}, ],
buttons: [{
text: '',
handler: data => {
this.scannerCAB();
let pass = this.votreCode;
this.verifierclient(this.codeclient, pass);
// console.log('Barcode data', this.votreCode);
// let pass = data.code;
//this.verifierclient(this.codeclient, pass);
}
},{
text: 'Annuler ',
handler: data => {
}
},
{
text: 'ok ',
handler: data => {
let pass = data.code;
this.verifierclient(this.codeclient, pass);
}
},
]
});
prompt.present({
keyboardClose: false
})
.then(() => this.donebtn = false);
}
Since my answer was "Trivial" hence "converted to comment" here's a repost of my answer.
A bit late response. I tried to achieve this today, and I made it like this:
Create a css class in your app.scss and add that class in the alert option "cssClass".
app.scss
.yourClass{
background-image: url(your-image-url);
background-position: center;
background-repeat: no-repeat;
background-size: contain;
}
These css values can be changed per your requirements.
And in the Alert:
buttons: [
{
text: '',
cssClass: 'yourClass',
handler: data => {}
}
]

How to fix preview Window and fab buttons of camera-preview?

I am using the following code to make a camera-based app. But the preview window is not fixed and easily bud dragging over the screen it replaces. Also fab buttons are in behind of preview window. How is possible to fix them over each other on the screen.
home.ts
constructor(public navCtrl: NavController, private cameraPreview: CameraPreview) {
this.startCamera();
}
startCamera() {
const cameraPreviewOpts: CameraPreviewOptions = {
x: 40,
y: 40,
width: window.screen.width-1,
height: window.screen.height-1,
camera: 'rear',
tapPhoto: true,
previewDrag: true,
toBack: false,
alpha: 1
};
this.cameraPreview.startCamera(cameraPreviewOpts).then(
(res) => {
console.log(res);
},
(err) => {
console.log(err);
});
}
showCamera(){
this.cameraPreview.show();
}
stopCamera(){
this.cameraPreview.stopCamera();
}
takePicture(){
const pictureOpts: CameraPreviewPictureOptions = {
width: 1280,
height: 1280,
quality: 85
}
this.cameraPreview.takePicture(pictureOpts).then(function(imgData){
console.log('Picture taken');
(<HTMLInputElement>document.getElementById('previewPicture')).src = 'data:image/jpeg;base64,' + imgData;
}, (err) => {
console.log(err);
});
}
}
home.html:
<ion-content padding>
<ion-fab right bottom>
<button ion-fab color="primary" (click)="takePicture()">
<ion-icon name="md-camera"></ion-icon>
</button>
</ion-fab>
</ion-content>
Basically you need to "send" camera preview to back of the page and disable dragging option.
Try this:
const cameraPreviewOpts: CameraPreviewOptions = {
x: 40,
y: 40,
width: window.screen.width-1,
height: window.screen.height-1,
camera: 'rear',
tapPhoto: true,
previewDrag: false,
toBack: true,
alpha: 1
};
Your html code seems to be ok so your "fab" button should become visible.
If you want to use preview on whole screen- change width & height accordingly (remove -1) also,
x & y determine where your preview vindow will start, so set to 0 if you want to use it on whole screen.
Hope it helps!

How to add "Follow the link popup" into TinyMCE 4

I implemented somethink like on this picture:
if you click on a link popup will appear and you can follow the link.
jQuery(function($){
/**
* add the follow link popup to all TinyMCE instances
*/
if (!window.tinymce) return;
tinymce.on('AddEditor', function( event ) {
tinymce.editors.forEach(function(editor) {
if (!editor.isFollowLinkAdded) {
editor.isFollowLinkAdded = true;
editor.on('blur', function(e) {
jQuery(e.target.contentDocument.body).find('#followLink').remove();
});
editor.on('click', function(e) {
var link = jQuery(e.target).closest('a');
jQuery(e.view.document.body).find('#followLink').remove();
if (link.length) {
e.preventDefault();
var POPUP_WIDTH = 215,
isRightSide = (jQuery(e.view.document).width()-e.pageX) >= POPUP_WIDTH,
boxCss = {
top: e.pageY,
padding: '6px 10px',
position: 'absolute',
backgroundColor: '#ffffff',
border: '1px solid #a8a8a8',
borderRadius: '2px',
boxShadow: '0 1px 3px rgba(0, 0, 0, 0.2)',
color: '#666666',
cursor: 'pointer',
whiteSpace: 'nowrap',
zIndex: 502
};
boxCss[(isRightSide) ? 'left' : 'right'] = (isRightSide) ? e.pageX : jQuery(e.view.document).width()-e.pageX;
jQuery('<a/>', {
href: link.attr('href'),
text: link.attr('href'),
target: '_blank'
}).css({
cursor: 'pointer',
display: 'inline-block',
maxWidth: '100px',
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap'
}).wrap(
jQuery('<p/>', {
text: 'Click to follow: ',
id: 'followLink',
}).on('click', function(){
var win = window.open(link.attr('href'), '_blank');
win.focus();
}).css(boxCss)
).parent().appendTo(e.view.document.body);
}
});
}
});
}, true );
});
The most recent version of TinyMCE 4 (4.5.3) includes the option to open a link in the right click menu of the editor - no need to write your own custom code.