Skip to content

Commit 861a5f2

Browse files
committed
Example Usage comment updated for all PHP components
1 parent b86da08 commit 861a5f2

29 files changed

Lines changed: 1443 additions & 284 deletions

components/Accordion.php

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,46 @@
2727
* ->add_item( 'About Course', '<p>Description...</p>' )
2828
* ->render();
2929
*
30-
* // Multiple items
30+
* // Multiple items, first open by default
3131
* Accordion::make()
3232
* ->add_item( 'About Course', '<p>Description...</p>' )
3333
* ->add_item( 'Requirements', '<p>Prerequisites...</p>' )
3434
* ->add_item( 'Instructor', '<p>Meet your instructor...</p>' )
3535
* ->default_open( array( 0 ) )
3636
* ->render();
3737
*
38-
* // With custom icon and template
38+
* // Multiple items open by default (indices 0 and 2)
3939
* Accordion::make()
40-
* ->add_item( 'Details', '', 'path/to/template.php', 'custom-icon' )
40+
* ->add_item( 'Overview', '<p>Course overview...</p>' )
41+
* ->add_item( 'Curriculum', '<p>Topics covered...</p>' )
42+
* ->add_item( 'FAQ', '<p>Common questions...</p>' )
43+
* ->default_open( array( 0, 2 ) )
44+
* ->render();
45+
*
46+
* // Only one item open at a time (allow_multiple = false)
47+
* Accordion::make()
48+
* ->add_item( 'Section 1', '<p>Content 1...</p>' )
49+
* ->add_item( 'Section 2', '<p>Content 2...</p>' )
4150
* ->allow_multiple( false )
4251
* ->render();
52+
*
53+
* // With custom icon per item
54+
* Accordion::make()
55+
* ->add_item( 'Resources', '', '', Icon::RESOURCES )
56+
* ->add_item( 'Downloads', '', '', Icon::DOWNLOAD_2 )
57+
* ->render();
58+
*
59+
* // With a PHP template file as content
60+
* Accordion::make()
61+
* ->add_item( 'Details', '', get_template_directory() . '/partials/details.php' )
62+
* ->render();
63+
*
64+
* // Extra HTML attributes on the wrapper
65+
* Accordion::make()
66+
* ->add_item( 'Notes', '<p>Some notes...</p>' )
67+
* ->attr( 'id', 'course-accordion' )
68+
* ->attr( 'class', 'my-custom-class' )
69+
* ->render();
4370
* ```
4471
*
4572
* @since 4.0.0
@@ -189,7 +216,7 @@ public function get(): string {
189216
'multiple' => $this->multiple,
190217
'defaultOpen' => $this->default_open,
191218
);
192-
$alpine_json = wp_json_encode( $alpine_config );
219+
$alpine_json = wp_json_encode( $alpine_config );
193220

194221
// Merge custom classes.
195222
$wrapper_classes = 'tutor-accordion';
@@ -206,9 +233,9 @@ public function get(): string {
206233
// Build items HTML.
207234
$items_html = '';
208235
foreach ( $this->items as $index => $item ) {
209-
$title = isset( $item['title'] ) ? $item['title'] : '';
210-
$icon = isset( $item['icon'] ) ? $item['icon'] : '';
211-
$panel_id = 'tutor-acc-panel-' . $index;
236+
$title = isset( $item['title'] ) ? $item['title'] : '';
237+
$icon = isset( $item['icon'] ) ? $item['icon'] : '';
238+
$panel_id = 'tutor-acc-panel-' . $index;
212239
$trigger_id = 'tutor-acc-trigger-' . $index;
213240

214241
$icon_html = $this->render_icon( $icon );
@@ -262,5 +289,4 @@ class="tutor-accordion-content"
262289
$items_html
263290
);
264291
}
265-
266292
}

components/Alert.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,46 @@
2020
*
2121
* Example usage:
2222
* ```
23+
* // Default (neutral) alert
2324
* Alert::make()
24-
* ->text( 'This is an alert' )
25+
* ->text( 'Your changes have been saved.' )
26+
* ->render();
27+
*
28+
* // Success alert with icon
29+
* Alert::make()
30+
* ->text( 'Course published successfully.' )
2531
* ->variant( Alert::SUCCESS )
2632
* ->icon( Icon::PRIME_CHECK_CIRCLE )
27-
* ->action( '<button class="...">Resume</button>' )
33+
* ->render();
34+
*
35+
* // Info alert with action button
36+
* Alert::make()
37+
* ->text( 'You have an incomplete quiz. Resume where you left off.' )
38+
* ->variant( Alert::INFO )
39+
* ->icon( Icon::INFO )
40+
* ->action( '<button class="tutor-btn tutor-btn-primary tutor-btn-small">Resume</button>' )
41+
* ->render();
42+
*
43+
* // Warning alert
44+
* Alert::make()
45+
* ->text( 'Your subscription expires in 3 days.' )
46+
* ->variant( Alert::WARNING )
47+
* ->icon( Icon::WARNING )
48+
* ->render();
49+
*
50+
* // Error alert with custom icon size
51+
* Alert::make()
52+
* ->text( 'Payment failed. Please try again.' )
53+
* ->variant( Alert::ERROR )
54+
* ->icon( Icon::CLOSE_CIRCLE, 24, 24 )
55+
* ->render();
56+
*
57+
* // Alert with extra HTML attributes
58+
* Alert::make()
59+
* ->text( 'Draft saved.' )
60+
* ->variant( Alert::SUCCESS )
61+
* ->attr( 'id', 'draft-alert' )
62+
* ->attr( 'x-show', 'showAlert' )
2863
* ->render();
2964
* ```
3065
*

components/AttachmentCard.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,39 @@
1818
* Class AttachmentCard
1919
*
2020
* Example Usage:
21+
* ```php
22+
* // Basic downloadable attachment
2123
* AttachmentCard::make()
2224
* ->file_name( 'lesson-plan.pdf' )
23-
* ->file_size( '1.2 MB' )
25+
* ->file_size( '1258291' ) // bytes — size_format() is applied internally
2426
* ->is_downloadable( true )
2527
* ->action_attr( '@click', 'downloadFile()' )
2628
* ->render();
2729
*
30+
* // Removable attachment (delete icon)
31+
* AttachmentCard::make()
32+
* ->file_name( 'assignment.docx' )
33+
* ->file_size( '524288' )
34+
* ->is_downloadable( false )
35+
* ->action_attr( '@click', 'removeFile(index)' )
36+
* ->render();
37+
*
38+
* // With Alpine.js dynamic bindings on title and meta
39+
* AttachmentCard::make()
40+
* ->title_attr( 'x-text', 'file.name' )
41+
* ->meta_attr( 'x-text', 'formatBytes(file.size)' )
42+
* ->action_attr( '@click.stop', 'removeFile(index)' )
43+
* ->render();
44+
*
45+
* // With extra attributes on the wrapper
46+
* AttachmentCard::make()
47+
* ->file_name( 'course-notes.pdf' )
48+
* ->file_size( '2097152' )
49+
* ->is_downloadable( true )
50+
* ->attr( 'data-id', '42' )
51+
* ->render();
52+
* ```
53+
*
2854
* @since 4.0.0
2955
*/
3056
class AttachmentCard extends BaseComponent {

components/Avatar.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,49 @@
2424
* Example usage:
2525
*
2626
* ```php
27-
* Avatar with user object/ID
27+
* // Avatar from a WP user ID (auto-resolves photo or initials)
2828
* Avatar::make()
29-
* ->user($user_id)
30-
* ->size(Size::SIZE_56)
29+
* ->user( $user_id )
30+
* ->size( Size::SIZE_56 )
3131
* ->render();
3232
*
33-
* Avatar with image source
33+
* // Avatar from a WP_User object
3434
* Avatar::make()
35-
* ->src('https://example.com/avatar.jpg')
36-
* ->size(Size::SIZE_20)
35+
* ->user( $user )
36+
* ->size( Size::SIZE_40 )
3737
* ->bordered()
3838
* ->render();
3939
*
40-
* Avatar with initials
40+
* // Avatar with explicit image URL
4141
* Avatar::make()
42-
* ->initials('SK')
43-
* ->size(Size::SIZE_32)
44-
* ->rounded(false)
42+
* ->src( 'https://example.com/avatar.jpg' )
43+
* ->alt( 'John Doe' )
44+
* ->size( Size::SIZE_32 )
4545
* ->render();
46+
*
47+
* // Avatar with initials fallback only
48+
* Avatar::make()
49+
* ->initials( 'JD' )
50+
* ->size( Size::SIZE_48 )
51+
* ->render();
52+
*
53+
* // Avatar with square shape (no border-radius)
54+
* Avatar::make()
55+
* ->user( $user_id )
56+
* ->size( Size::SIZE_64 )
57+
* ->shape( 'square' )
58+
* ->render();
59+
*
60+
* // Avatar with border and custom attributes
61+
* Avatar::make()
62+
* ->src( 'https://example.com/pic.jpg' )
63+
* ->size( Size::SIZE_20 )
64+
* ->bordered()
65+
* ->attr( 'data-user-id', $user_id )
66+
* ->render();
67+
*
68+
* // Retrieve HTML string without echoing
69+
* $html = Avatar::make()->user( $user_id )->size( Size::SIZE_24 )->get();
4670
* ```
4771
*
4872
* @since 4.0.0

components/Badge.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,54 @@
2020
*
2121
* Example usage:
2222
* ```
23+
* // Primary badge
2324
* Badge::make()
24-
* ->label( 'Primary' )
25+
* ->label( 'New' )
2526
* ->variant( Badge::PRIMARY )
27+
* ->render();
28+
*
29+
* // Badge with SVG icon markup
30+
* Badge::make()
31+
* ->label( 'Certified' )
32+
* ->variant( Badge::SUCCESS )
2633
* ->icon( '<svg>...</svg>' )
2734
* ->render();
2835
*
36+
* // Badge with icon name (SvgIcon slug)
37+
* Badge::make()
38+
* ->label( 'Warning' )
39+
* ->variant( Badge::WARNING )
40+
* ->icon( Icon::WARNING, 14, 14 )
41+
* ->render();
42+
*
43+
* // Badge with icon as URL (img tag is generated)
44+
* Badge::make()
45+
* ->label( 'Verified' )
46+
* ->variant( Badge::SUCCESS_SOLID )
47+
* ->icon( 'https://example.com/check.png', 16, 16 )
48+
* ->render();
49+
*
50+
* // Rounded (pill) badge
2951
* Badge::make()
3052
* ->label( 'Points: 20' )
53+
* ->variant( Badge::HIGHLIGHT )
3154
* ->rounded()
3255
* ->render();
56+
*
57+
* // Error / disabled badge without icon
58+
* Badge::make()
59+
* ->label( 'Inactive' )
60+
* ->variant( Badge::DISABLED )
61+
* ->render();
62+
*
63+
* // Badge with no variant (default style) and extra attrs
64+
* Badge::make()
65+
* ->label( 'Draft' )
66+
* ->attr( 'data-status', 'draft' )
67+
* ->render();
68+
*
69+
* // Retrieve HTML string without echoing
70+
* $html = Badge::make()->label( 'Info' )->variant( Badge::INFO )->get();
3371
* ```
3472
*
3573
* @since 4.0.0

components/Button.php

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use Tutor\Components\Constants\Size;
1717
use Tutor\Components\Constants\Variant;
18-
use Tutor\Components\Constants\Color;
1918

2019
defined( 'ABSPATH' ) || exit;
2120

@@ -24,13 +23,87 @@
2423
*
2524
* Example usage:
2625
* ```
26+
* // Primary button (default)
2727
* Button::make()
2828
* ->label( 'Enroll Now' )
29+
* ->render();
30+
*
31+
* // Button with size and variant
32+
* Button::make()
33+
* ->label( 'Save Changes' )
2934
* ->size( Size::LARGE )
3035
* ->variant( Variant::PRIMARY )
31-
* ->icon( 'tutor-icon-play' )
32-
* ->attr( 'data-id', 101 )
3336
* ->render();
37+
*
38+
* // Button with left icon
39+
* Button::make()
40+
* ->label( 'Add Course' )
41+
* ->icon( Icon::PLUS )
42+
* ->size( Size::MEDIUM )
43+
* ->variant( Variant::PRIMARY )
44+
* ->render();
45+
*
46+
* // Button with right icon and custom icon size/color
47+
* Button::make()
48+
* ->label( 'Download' )
49+
* ->icon( Icon::DOWNLOAD_2, 'right', 18, Color::BRAND )
50+
* ->variant( Variant::OUTLINE )
51+
* ->render();
52+
*
53+
* // Icon-only button (no visible label, uses aria-label)
54+
* Button::make()
55+
* ->label( 'Delete' )
56+
* ->icon( Icon::DELETE_2 )
57+
* ->icon_only()
58+
* ->variant( Variant::GHOST )
59+
* ->size( Size::SMALL )
60+
* ->render();
61+
*
62+
* // Disabled button
63+
* Button::make()
64+
* ->label( 'Submit' )
65+
* ->variant( Variant::PRIMARY )
66+
* ->disabled()
67+
* ->render();
68+
*
69+
* // Block (full-width) button
70+
* Button::make()
71+
* ->label( 'Continue' )
72+
* ->variant( Variant::PRIMARY )
73+
* ->block()
74+
* ->render();
75+
*
76+
* // Link-styled button rendered as <a> tag
77+
* Button::make()
78+
* ->label( 'View Course' )
79+
* ->variant( Variant::LINK )
80+
* ->tag( 'a' )
81+
* ->attr( 'href', get_permalink( $course_id ) )
82+
* ->render();
83+
*
84+
* // Destructive button
85+
* Button::make()
86+
* ->label( 'Delete Course' )
87+
* ->variant( Variant::DESTRUCTIVE )
88+
* ->size( Size::SMALL )
89+
* ->render();
90+
*
91+
* // Secondary/outline button with data attribute
92+
* Button::make()
93+
* ->label( 'Cancel' )
94+
* ->variant( Variant::SECONDARY )
95+
* ->attr( 'data-id', $course_id )
96+
* ->render();
97+
*
98+
* // Button with RTL-flippable directional icon
99+
* Button::make()
100+
* ->label( 'Next' )
101+
* ->icon( Icon::CHEVRON_RIGHT, 'right' )
102+
* ->flip_rtl()
103+
* ->render();
104+
*
105+
* // Retrieve HTML string without echoing
106+
* $html = Button::make()->label( 'Get Started' )->variant( Variant::PRIMARY )->get();
34107
* ```
35108
*
36109
* @since 4.0.0
@@ -403,5 +476,4 @@ public function get(): string {
403476

404477
return $this->component_string;
405478
}
406-
407479
}

0 commit comments

Comments
 (0)