What is the best way to have text wrap around an icon in my React application?

I am facing an issue while trying to display the note description over the trash icon in a React app. I have tried various methods but can't seem to achieve the desired effect. Can anyone guide me on how to get this layout?

Here is what I intend to achieve:

And here is what I currently have:

This is my code snippet in React:

import React from 'react';
import { FiTrash2, FiCalendar, FiBookmark } from 'react-icons/fi';

import { NoteType } from '../../utils/types';
import { formatDate } from '../../utils/functions';

import './styles.css';

interface NoteItem {
    note: NoteType;
    onEdit(): void;
    onDelete(): void;
}

const NoteItem: React.FC<NoteItem> = ({ note, onEdit, onDelete }) => {
    return (
        <div className="NoteItem" style={{ borderColor: note.color }}>
            <div className="info" onClick={ onEdit }>
                <p>{ note.description }</p>
                
                <div className="rows">
                    <div className="row">
                        <FiBookmark size={ 18 } className="icon" color={ note.color } />
                        <p>{ note.status }</p>
                    </div>
                    <div className="row">
                        <FiCalendar size={ 18 } className="icon" color={ note.color } />
                        <p>{ formatDate(note.created_at) }</p>
                    </div>
                </div>
            </div>

            <div className="buttons">
                <button title="Deletar" onClick={ onDelete }>
                    <FiTrash2 size={ 18 } className="remove" />
                </button>
            </div>
        </div>
    );
}

export default NoteItem;

If anyone has any suggestions or solutions, please feel free to share them. Your help will be greatly appreciated!

Answer №1

To achieve the desired output, you can utilize the float property. Simply add float:right to the buttons div. Here is a live example demonstrating this -

Check out the JS fiddle here

Keep in mind that adjustments might be needed in the JSX structure too.

Answer №2

To achieve this, you need to enclose the rows within the Paragraph tag and specify a particular width for the rows. Make sure to place it first in the structure and apply the style float: right.

const NoteItemModule: React.FC<NoteItem> = ({ note, onEdit, onDelete }) => {
    return (
        <div className="NoteItem" style={{ borderColor: note.color }}>
            <div className="info" onClick={ onEdit }>
                <p>
                <div className="rows" style="float:right; width:170px;">
                    <div className="row">
                        <FiBookmark size={ 18 } className="icon" color={ note.color } />
                        <p>{ note.status }</p>
                    </div>
                    <div className="row">
                        <FiCalendar size={ 18 } className="icon" color={ note.color } />
                        <p>{ formatDate(note.created_at) }</p>
                    </div>
                </div>
                  { note.description }
                </p>

            </div>

            <div className="buttons">
                <button title="Deletar" onClick={ onDelete }>
                    <FiTrash2 size={ 18 } className="remove" />
                </button>
            </div>
        </div>
    );
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with text-nowrap not functioning as intended within Bootstrap 4.5 table cells

Is there a way to eliminate the space between two columns in my layout? I want to get rid of the highlighted space below. I attempted using text-nowrap, but it didn't achieve the desired result. <link href="https://stackpath.bootstrapcdn.co ...

Encountered a error 500 while attempting to POST using Postman in Node.js

After successfully setting up the server, I encountered an issue when attempting to create a user using Postman with the details in Application/JSON format. The server responded with: POST /sign-up 500. Initially, I tried specifying utf-8 without succes ...

Is it possible to create and manage a hierarchical menu in React (Next.js) using a generic approach?

Over the past few days, I've been working on a project involving a navigation bar built with TypeScript and React (Next.js). Up until now, I've only had a single level navigation, but now I'm looking to upgrade to a multi-level navigation me ...

Testing onClick using Jest when it is not a callback function in props

I have discovered various ways to utilize mock functions in jest for spying on callback functions passed down to a component, but I have not found any information on testing a simple onClick function defined within the same component. Here is an example f ...

JavaScript to toggle the visibility of elements when they move outside of a specified container

Check out this js+html/css project I worked on: http://jsfiddle.net/A1ex5andr/xpRrf/ It functions as intended - opening and closing with the use of .advSearch-btn to open/close, and .advSearch-control .canc to close. However, I am facing an issue where it ...

What is causing the warnings for a functional TypeScript multidimensional array?

I have an array of individuals stored in a nested associative array structure. Each individual is assigned to a specific location, and each location is associated with a particular timezone. Here is how I have defined my variables: interface AssociativeArr ...

Uniting 2 streams to create a single observable

I am in the process of merging 2 different Observables. The first Observable contains a ShoppingCart class, while the second one holds a list of ShoppingItems. My goal is to map the Observable with shopping cart items (Observable<ShoppingItems) to the i ...

Comprehending the concept of error and data callbacks in functions

I'm feeling a bit puzzled about how the function(err, data) callback operates. Is the first argument always designated to handle errors? And what happens with the rest of the arguments in a scenario like function(x, y, z, a, b, c)? How exactly does ...

retrieving XML information into a div using Ajax and JavaScript

I am currently working on developing a chat application and facing an issue with fetching all logged in users into a div with the ID "chat_members". Despite confirming that the XML file structure is correct, the JavaScript code alongside AJAX does not seem ...

BottomNavigation wrapping React Router is failing to load the updated component

I'm struggling to understand why I can't seem to load the DMO page from a BottomNavigation component. Navigating to "/dom" works fine, but clicking the buttons doesn't do anything. The initial "/" loads perfectly. Any ide ...

Looking to utilize flash player within React Electron Web View

I'm currently working on a React-Electron project and have integrated the react-electron-web-view package, which utilizes browserify for displaying websites. However, I've encountered an issue with certain websites that still rely on Flash Player ...

Dynamic controller in TypeScript with React Hook Form

Is there a way to ensure that the fieldName is always inside the control? Passing a field name that doesn't exist in the form causes issues for me, so I'm looking for a solution. Can anyone help? import { Control, Controller } from 'react-ho ...

Is there a way to launch QTP from JavaScript without relying on ActiveXObject?

Is there a way to call QTP from JavaScript without relying on ActiveXObject? I would appreciate any guidance on how to accomplish this task. Thanks in advance, Ramya. ...

The consistency of values remains constant throughout all Ajax requests

I am presenting the code snippet below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title>Document</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" ...

Effortless AJAX Submission and MySQL Data Refresh

I've hit a roadblock and can't seem to figure things out. I'm getting rid of my current code because it's not working well across different browsers, particularly when it comes to ajax submission. Could someone please provide me with a ...

What could be the reason for the next.js Script tag not loading the third-party script when using the beforeInteractive strategy?

I have been trying to understand how the next.js Script tag with the beforeInteractive strategy works. I am currently testing it with lodash, but I keep encountering a ReferenceError: _ is not defined. I was under the impression that when a script is loade ...

Validating emails using angular material chips

I'm currently working on implementing a form that utilizes input chips to facilitate sending messages to multiple email addresses. While I've made progress in making the form functional, I'm facing difficulties in displaying error messages w ...

Retrieve a collection of nested dictionaries containing flask and angular data

In my app development journey with flask and ionic(angular), I'm working on returning a JSON list. Here's the python code snippet: def get-stocks(): # Select all stocks cursor.execute("""SELECT * FROM `tbl_symbol_index`"" ...

Using regex in PHP to wrap the <ul> tag with <div> is a useful technique

My html snippet looks like this. <ul style="margin-left: 240px;"> <li>One</li> <li>Three <ul> <li>dfdf</li> </ul> </li> <li>dfds</li> </ul> ...

jquery monitors an element to see if it contains a particular attribute, then takes action accordingly

I'm attempting to conceal a div when an anchor tag (a) has a particular href, and reveal it when the href is different. This is what I've tried: if($('a[href="#intro"]').not(".active")) { $('.navbar-brand').hide();} else ...