Giter Site home page Giter Site logo

php-lucide's Introduction

php-lucide

PHP Library for Lucide.

For more information on Lucide itself, please refer to their README.

Installation

Install php-lucide using Composer.

composer require natewiebe13/php-lucide

Versioning

This library uses Semantic Versioning as a versioning strategy. This covers the public API, but does not guarantee backwards compatibility with breaking changes made by Lucide (ex: icon name changes). Any large backwards compatibility breaks made by Lucide may result in a new major version of this library, but will be determined on a case by case basis. In the event that an icon naming change is made, the Aliases feature can be used to assist migrating to the new icon name.

Usage

Icons

Icons are retrieved from an IconManager.

<?php
$icons = new \Lucide\IconManager();
?>

<!-- Display the 'anchor' icon -->
<?php echo $icons->getIcon('anchor'); ?>

<!-- Get creative! -->
<button class="icon-button">
    Learn More <?= $icons->getIcon('arrow-right'); ?>
</button>

Lucide\IconManager::getIcon() returns an Icon object. To render the icon html itself, either cast the Icon as a string or call its render() function.

$icons->getIcon('anchor'); // Returns an Icon object
$html = $icons->getIcon('anchor')->render(); // Returns the icon's html
echo $icons->getIcon('anchor'); // Outputs the icon's html, since it is cast as a string

Attributes

Attributes can be modified on both the IconManager and on Icon objects. Attributes can be modified directly using the setAttribute(s) functions or by using the helper functions.

Attribute changes on the IconManager will affect all Icon objects created by the IconManager. Changes on Icon objects will only affect the individual icons.

// Use on the IconManager instance to set default attributes for all icons
$icons->setAttributes(['stroke' => '#fff', 'stroke-width' => 2]);
$icons->setAttribute('stroke', '#fff');

$icons->setSize(24);
$icons->setColor('#fff');
$icons->setWeight(2);
$icons->addCssClass('foo');

// Or use on a single icon to only affect that one
echo $icons->getIcon('alert-triangle')->setColor('red')->setAttribute('data-alert', 'true');

Accessibility

When getting an Icon, alt text can be passed as an argument or can be set on the Icon at a later time.

$icons->getIcon('anchor', [], 'Icon of an anchor');

$icon->setAltText('Icon of an anchor');

Aliases

Aliases can be set to make larger changes across a theme easier, such as replacing the actual icon used for a specific use case. For example, what if for the close button icon, you wanted to switch from using the x icon to x-circle. Instead of having the icon name hardcoded, you could use an alias for the use case and update the value in one place. Aliases are set on the IconManager.

$icons->addAlias('close-button', 'x');

Contributing

Feel free to open up issues and PRs for suggestions.

License

Licensed under the MIT License.

The icons in this code are from Lucide. Which is licensed under the ISC License.

php-lucide's People

Contributors

natewiebe13 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.