New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Icons in bootstrap widgets #5207
Comments
Suppose the original idea with the inbuilt yii2-bootstrap was to avoid building php code for simple HTML markup except for complex markup where widgets are available. Probably the yii core team may validate this or explain this better. Regarding usage of icons, I think bootstrap by default only supports glyphicons. But then, developers tend to combine other css frameworks and icon packages as well, as you mentioned. Hence, the code in current yii bootstrap extension needs to be scalable to accept more such situations to auto generate the html markup. (probably the reason maybe the original idea to allow any HTML markup). I remember creating a separate yii2-icons extension - to manage and use icon frameworks across Yii - which is discussed to some extent here, along with bootstrap html helpers. But I think it depends on what is more easier or scalable for each developer. |
Referring an old related discussion #1285 on this. |
The main issue I have is that the label is supposed to be a simple string, it's even html encoded by default. Adding an icon to it right now is cumbersome and feels like a hack, because you have to disable the automatic encoding (and then manually encode, depending on where the text comes from). |
Please also add the ability to add icons to the NavBar and in particular to the brandLabel which actually prohibits the placement of anything else but text! |
The items in a navbar are rendered by Nav, and I've added icon support to that. brandLabel is not html encoded, so it's not an issue there, but I could add a brandIcon property as well, I think the code would look nicer. Right now you can do: NavBar::begin([
'brandLabel' => Icon::icon('cog') . ' ' . Yii::t('app', 'My awesome app'),
]); With brandIcon it would look like this: NavBar::begin([
'brandIcon' => Icon::icon('cog'),
'brandLabel' => Yii::t('app', 'My awesome app'),
]); |
Both look cool, thanks. Most important is to document it all though! :) |
@nkovacs what is the status of this one? Your solution seems to be fantastic and as I run right now in exactly the situation you describe (lots of buttons in a button group) this would hep me a lot. |
No, it's not. The Yii devs have to review and merge it. |
A couple of things:
|
Why did you not just take my version? There are several problems with your implementation:
|
To be honest I have missed it. Sorry.
Fair point - fixed.
I am usure, if this can be done now, since it may be a BC break.
For thirdparty icon library you should use raw label composition just as for any non bootstrap widget.
Actually for the icons it is unlikely to be used in collaplse, but alright I have add it. |
Then this feature will not be very useful to me, and I'm back to square one, having to extend all the widgets to hack on proper icon support. |
That is not yet decided. |
I have manage to bypass this: you will be able to specify icon as composed HTML. |
Another implementation: yiisoft/yii2-bootstrap#32 |
Migrated to yiisoft/yii2-bootstrap#42 |
With Yiistrap, you could do this, for example:
with Yii 2, it's more complicated:
If you want to have labels too, you have to concatenate and you should manually encode them too. This, plus all the html makes the code less readable compared to Yiistrap.
I have modified the yii2-bootstrap widgets to make it possible to do this:
Note: the reason for using
Icon::icon('foo')
instead of just'foo'
is to be able to change the icon to font awesome or any other plugin which uses different css classes.The text was updated successfully, but these errors were encountered: