Introduction
Within Filament schemas, prime components are the most basic building blocks that can be used to insert arbitrary content into a schema, such as text and images. As the name suggests, prime components are not divisible and cannot be made simpler. Filament provides a set of built-in prime components: You may also create your own custom components to add your own arbitrary content to a schema. In this example, prime components are being used to display instructions to the user, a QR code that the user can scan, and list of recovery codes that the user can save:Filament\Schemas\Components namespace. They reside within the schema array of components.
Text component
Text can be inserted into a schema using theText component. Text content is passed to the make() method:
HtmlString object to the make() method:
Be aware that you will need to ensure that the HTML is safe to render, otherwise your application will be vulnerable to XSS attacks.
str() helper to convert Markdown to HTML, and then transform it into an HtmlString object:
Customizing the text color
You may set a color for the text:Using a neutral color
By default, the text color is set togray, which is typically fairly dim against its background. You can darken it using the color('neutral') method:
Displaying as a “badge”
By default, text is quite plain and has no background color. You can make it appear as a “badge” instead using thebadge() method. A great use case for this is with statuses, where may want to display a badge with a color that matches the status:
Adding an icon to the badge
You may add other things to the badge, like an icon:Customizing the text size
Text has a small font size by default, but you may change this toTextSize::ExtraSmall, TextSize::Medium, or TextSize::Large.
For instance, you may make the text larger using size(TextSize::Large):
Customizing the font weight
Text entries have regular font weight by default, but you may change this to any of the following options:FontWeight::Thin, FontWeight::ExtraLight, FontWeight::Light, FontWeight::Medium, FontWeight::SemiBold, FontWeight::Bold, FontWeight::ExtraBold or FontWeight::Black.
For instance, you may make the font bold using weight(FontWeight::Bold):
Customizing the font family
You can change the text font family to any of the following options:FontFamily::Sans, FontFamily::Serif or FontFamily::Mono.
For instance, you may make the font monospaced using fontFamily(FontFamily::Mono):
Adding a tooltip to the text
You may add a tooltip to the text using thetooltip() method:
Using JavaScript to determine the content of the text
You can use JavaScript to determine the content of the text. This is useful if you want to display a different message depending on the state of a form field, without making a request to the server to re-render the schema. To allow this, you can use thejs() method:
$state and $get() utilities are available in the JavaScript context, so you can use them to get the state of fields in the schema.
Icon component
Icons can be inserted into a schema using theIcon component. Icons are passed to the make() method:
Customizing the icon color
You may set a color for the icon:Customizing the icon size
The default icon size isIconSize::Medium, but you may customize the size to be either IconSize::ExtraSmall, IconSize::Small, IconSize::Large, IconSize::ExtraLarge or IconSize::TwoExtraLarge:
Adding a tooltip to the icon
You may add a tooltip to the icon using thetooltip() method:
Image component
Images can be inserted into a schema using theImage component. The image URL and alt text are passed to the make() method:
Customizing the image size
You may customize the image size by passing aimageWidth() and imageHeight(), or both with imageSize():
Aligning the image
You may align the image to the start (left in left-to-right interfaces, right in right-to-left interfaces), center, or end (right in left-to-right interfaces, left in right-to-left interfaces) using thealignStart(), alignCenter() or alignEnd() methods:
Alignment enum to the alignment() method:
Adding a tooltip to the image
You may add a tooltip to the image using thetooltip() method:
Unordered list component
Unordered lists can be inserted into a schema using theUnorderedList component. The list items, comprising plain text or text components, are passed to the make() method:
Customizing the bullet size
If you are modifying the text size of the list content, you will probably want to adjust the size of the bullets to match. To do this, you can use thesize() method. Bullets have small font size by default, but you may change this to TextSize::ExtraSmall, TextSize::Medium, or TextSize::Large.
For instance, you may make the bullets larger using size(TextSize::Large):
Adding extra HTML attributes to a prime component
You can pass extra HTML attributes to the component via theextraAttributes() method, which will be merged onto its outer HTML element. The attributes should be represented by an array, where the key is the attribute name and the value is the attribute value:
extraAttributes() multiple times will overwrite the previous attributes. If you wish to merge the attributes instead, you can pass merge: true to the method.